Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ipv4 && ipv6 parm #291

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
4 changes: 1 addition & 3 deletions client/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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() {
Expand Down