ifcfg

Get network interfaces information

3 releases

0.1.2 Jun 8, 2021
0.1.1 Jun 6, 2021
0.1.0 Mar 12, 2021
Download history 124/week @ 2024-06-13 70/week @ 2024-06-20 114/week @ 2024-06-27 243/week @ 2024-07-04 416/week @ 2024-07-11 302/week @ 2024-07-18 404/week @ 2024-07-25 362/week @ 2024-08-01 354/week @ 2024-08-08 127/week @ 2024-08-15 261/week @ 2024-08-22 213/week @ 2024-08-29 157/week @ 2024-09-05 233/week @ 2024-09-12 194/week @ 2024-09-19 174/week @ 2024-09-26

809 downloads per month
Used in 3 crates (2 directly)

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) is a Rust library to get network interfaces information for Windows/Linux/Mac

Requirements

  • Rust

Include in project

[dependencies]
ifcfg = "0.1.2"

Example

use ifcfg;

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

Compile

cargo b

Tests

cargo t

Run the included example

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: "",
    },
]


License: MIT/Apache

Dependencies

~2.3–3.5MB
~71K SLoC