3 个版本

0.1.2 2021 年 6 月 8 日
0.1.1 2021 年 6 月 6 日
0.1.0 2021 年 3 月 12 日

1264网络编程

Download history 444/week @ 2024-03-13 335/week @ 2024-03-20 207/week @ 2024-03-27 364/week @ 2024-04-03 516/week @ 2024-04-10 453/week @ 2024-04-17 297/week @ 2024-04-24 480/week @ 2024-05-01 513/week @ 2024-05-08 374/week @ 2024-05-15 409/week @ 2024-05-22 390/week @ 2024-05-29 143/week @ 2024-06-05 156/week @ 2024-06-12 61/week @ 2024-06-19 98/week @ 2024-06-26

每月 480 次下载
3 个 Crates 中使用 (直接使用 2 个)

MIT/Apache

76KB
2K SLoC

Rust 1.5K SLoC // 0.0% comments C 561 SLoC // 0.0% comments

IFCFG

Crates.io Documentation Build Status

IFCFG (ifconfig) 是一个用于获取 Windows/Linux/Mac 网络接口信息的 Rust 库

需求

  • Rust

将库包含在项目中

[dependencies]
ifcfg = "0.1.2"

示例

use ifcfg;

fn main() -> ifcfg::Result<()> {
    let ifaces = ifcfg::IfCfg::get().expect("could not get interfaces");
    println!("{:#?}", &ifaces);
    Ok(())
}

编译

cargo b

测试

cargo t

运行包含的示例

cargo run --example interfaces
   Compiling ifcfg v0.1.0 (/root/ifcfg)
    Finished dev [optimized + debuginfo] target(s) in 0.63s
     Running `target/debug/examples/interfaces`
[
    IfCfg {
        name: "lo",
        mac: "00:00:00:00:00:00",
        addresses: [
            InterfaceAddress {
                address_family: IPv6,
                address: Some(
                    [::1]:0,
                ),
                mask: Some(
                    [ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]:0,
                ),
                hop: None,
            },
            InterfaceAddress {
                address_family: IPv4,
                address: Some(
                    127.0.0.1:0,
                ),
                mask: Some(
                    255.0.0.0:0,
                ),
                hop: Some(
                    Destination(
                        127.0.0.1:0,
                    ),
                ),
            },
            InterfaceAddress {
                address_family: Packet,
                address: None,
                mask: None,
                hop: None,
            },
        ],
        description: "",
    },
    IfCfg {
        name: "ens33",
        mac: "00:0c:29:0a:e0:b4",
        addresses: [
            InterfaceAddress {
                address_family: IPv6,
                address: Some(
                    [fe80::20c:29ff:fe0a:e0b4%2]:0,
                ),
                mask: Some(
                    [ffff:ffff:ffff:ffff::]:0,
                ),
                hop: None,
            },
            InterfaceAddress {
                address_family: IPv6,
                address: Some(
                    [fd15:4ba5:5a2b:1008:20c:29ff:fe0a:e0b4]:0,
                ),
                mask: Some(
                    [ffff:ffff:ffff:ffff::]:0,
                ),
                hop: None,
            },
            InterfaceAddress {
                address_family: IPv4,
                address: Some(
                    192.168.2.3:0,
                ),
                mask: Some(
                    255.255.255.0:0,
                ),
                hop: Some(
                    Broadcast(
                        192.168.2.255:0,
                    ),
                ),
            },
            InterfaceAddress {
                address_family: Packet,
                address: None,
                mask: None,
                hop: None,
            },
        ],
        description: "",
    },
]


许可: MIT/Apache

依赖项

~2.2–3MB
~69K SLoC