A cross-platform library for retrieving network interface information.
This crate provides a simple and consistent API for querying network interface details across different operating systems. It supports Unix-like systems (Linux, macOS, *BSD) and Windows.
if_indextoname
and if_nametoindex
Add this to your Cargo.toml
:
[dependencies]
getifaddrs = "0.1"
use getifaddrs::{getifaddrs, InterfaceFlags};
fn main() -> std::io::Result<()> {
for interface in getifaddrs()? {
println!("Interface: {}", interface.name);
println!(" Address: {}", interface.address);
if let Some(netmask) = interface.netmask {
println!(" Netmask: {}", netmask);
}
println!(" Flags: {:?}", interface.flags);
if interface.flags.contains(InterfaceFlags::UP) {
println!(" Status: Up");
} else {
println!(" Status: Down");
}
println!();
}
Ok(())
}
This project is licensed under the MIT License.