Compare commits

..

No commits in common. "a315e2662c09760f06d54d6da97431af6597cebc" and "b1255c451e7b31fef1a6e066de6eaff36d1c6769" have entirely different histories.

3 changed files with 2 additions and 38 deletions

View File

@ -14,5 +14,4 @@ path = "src/nettest.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
chrono = "0.4.19"
clap = { version = "3.1.2", features = ["derive"] }

View File

@ -1,3 +0,0 @@
#!/bin/sh
docker run --rm --user "$(id -u)":"$(id -g)" -v "$PWD":/usr/src/hardware-tests -w /usr/src/hardware-tests rust:1.59 cargo build --release

View File

@ -1,6 +1,5 @@
use chrono::prelude::*;
use clap::{Parser, Subcommand};
use std::{fs,process};
use std::process;
#[derive(Parser)]
#[clap(name = "Bit Goblin Network Tester", author, version, about = "Network testing app.", long_about = None)]
@ -17,14 +16,6 @@ enum Commands {
#[clap(default_value_t = String::from("8.8.8.8"))]
host: String
},
// bandwidth test subcommand
Bandwidth {
#[clap(default_value_t = String::from("https://www.bitgoblin.tech/hardware-tests/export-01.mp4"))]
download: String,
#[clap(default_value_t = String::from("./tempfile"))]
output: String,
},
}
fn main() {
@ -32,8 +23,7 @@ fn main() {
// map subcommands back to the main command
match &cli.command {
Commands::Ping { host } => ping_host(host),
Commands::Bandwidth { download, output } => bandwidth_test(download, output)
Commands::Ping { host } => ping_host(host)
}
}
@ -54,25 +44,3 @@ fn ping_host(host: &str) {
// print out the ping results from stdout
println!("{}", String::from_utf8_lossy(&output.stdout));
}
// timed file copy test to guage bandwidth speeds
fn bandwidth_test(download: &str, output: &str) {
println!("Testing network bandwidth by downloading {}", download, output);
// get start time so we can track how long it takes to complete
let start_time = Utc::now();
// do the download
// get finish time
let finish_time = Utc::now();
// compute time to complete
let comp_time = finish_time - start_time;
println!("{}", comp_time.num_milliseconds());
// clean up the test file
match fs::remove_file(output) {
Ok(()) => println!("Cleaning up..."),
Err(e) => println!("There was a problem during cleanup - {}", e),
}
}