From c903ae7e92770b41fd3c85a390326462cbd1c86a Mon Sep 17 00:00:00 2001 From: Asuka Minato Date: Wed, 14 Feb 2024 16:03:10 +0000 Subject: [PATCH] add ipv4 & ipv6 parm --- client/src/main.rs | 14 ++++++++++++++ client/src/status.rs | 4 +--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/client/src/main.rs b/client/src/main.rs index 710a6839..b6982463 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -96,6 +96,20 @@ pub struct Args { help = "ip info source" )] ip_source: String, + #[arg( + long = "ipv4-address", + env = "SSR_IPV4_ADDRESS", + default_value = "ipv4.google.com:80", + help = "ipv4 check address" + )] + ipv4_address: String, + #[arg( + long = "ipv6-address", + env = "SSR_IPV6_ADDRESS", + default_value = "ipv6.google.com:80", + help = "ipv6 check address" + )] + ipv6_address: String, #[arg(long = "json", help = "use json protocol, default:false")] json: bool, #[arg(short = '6', long = "ipv6", help = "ipv6 only, default:false")] diff --git a/client/src/status.rs b/client/src/status.rs index a3022840..0d13d6a9 100644 --- a/client/src/status.rs +++ b/client/src/status.rs @@ -24,8 +24,6 @@ use stat_common::server_status::StatRequest; const SAMPLE_PERIOD: u64 = 1000; //ms const TIMEOUT_MS: u64 = 1000; -static IPV4_ADDR: &str = "ipv4.google.com:80"; -static IPV6_ADDR: &str = "ipv6.google.com:80"; pub fn get_uptime() -> u64 { fs::read_to_string("/proc/uptime") @@ -260,7 +258,7 @@ pub fn get_network(args: &Args) -> (bool, bool) { if network.iter().any(|&x| x) { return network.into(); } - let addrs = vec![IPV4_ADDR, IPV6_ADDR]; + let addrs = vec![&args.ipv4_address, &args.ipv6_address]; for (idx, probe_addr) in addrs.into_iter().enumerate() { let _ = probe_addr.to_socket_addrs().map(|mut iter| { if let Some(addr) = iter.next() {