Skip to content

Commit

Permalink
fix: get ip from interface name
Browse files Browse the repository at this point in the history
  • Loading branch information
zu1k committed Nov 7, 2021
1 parent 232e08e commit 6acade0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "sdusrun"
version = "0.4.0"
version = "0.4.1"
authors = ["zu1k <i@lgf.im>"]
edition = "2021"
description = "srun login"
description = "SRun3000 login"
readme = "README.md"
homepage = "https://github.com/zu1k/sdusrun"
repository = "https://github.com/zu1k/sdusrun"
Expand Down
7 changes: 6 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn get_ip_by_if_name(if_name: &str) -> Option<String> {
if i.is_up() && i.name.contains(if_name) && !i.ips.is_empty() {
for ip in i.ips {
if ip.is_ipv4() {
return Some(ip.to_string());
return Some(ip.ip().to_string());
}
}
}
Expand Down Expand Up @@ -92,6 +92,11 @@ fn test_get_ips() {
select_ip();
}

#[test]
fn test_get_ip_by_name() {
println!("{:?}", get_ip_by_if_name("wlp3s0"));
}

#[test]
fn test_tcp_ping() {
let p = tcp_ping("baidu.com:80");
Expand Down

0 comments on commit 6acade0

Please sign in to comment.