Cross-platform library for enumerating network interfaces with metadata.
netdev provides a unified API for discovering local network interfaces
and retrieving commonly used metadata across platforms.
- Enumerate all available network interfaces
- Detect the default network interface
- Retrieve interface metadata:
- Interface type
- MAC address
- IPv4 / IPv6 addresses and prefixes
- MTU, flags, operational state, etc...
- Native traffic statistics (RX/TX bytes) for each interface
- Designed for cross-platform
See the Interface struct documentation for more details.
- Linux
- macOS
- Windows
- Android
- iOS
- BSDs
Add netdev to your Cargo.toml:
[dependencies]
netdev = "0.48"| Feature | Default | Effect |
|---|---|---|
gateway |
Yes | Adds default-interface and gateway lookups, gateway addresses, and DNS servers. |
android-extra |
Yes | Uses Android APIs through JNI for additional traffic, DNS, DHCP, and Wi-Fi metadata. |
apple-system-configuration-extra |
Yes | Enables additional macOS SystemConfiguration bindings. Interface metadata collection also works with this feature disabled. |
apple-wifi-extra |
No | Reads macOS Wi-Fi transmit speed through CoreWLAN. This can perform synchronous IPC during enumeration. |
serde |
No | Enables serialization and deserialization of interface data. |
For more details, see examples or doc.
- Linux uses routes and destination rules to choose a UDP lookup destination outside more-specific prefixes when possible. The kernel selects the route. When the table is unavailable, it uses a fixed destination, as do several other platforms. A split VPN can affect that fallback.
- On Android, the host must initialize
ndk-contextbefore the first interface or traffic-counter lookup withandroid-extra. Some Android runtimes do this during startup. A missing context aborts the process in builds usingpanic = "abort". Android network and Wi-Fi metadata also depend on app permissions such asACCESS_NETWORK_STATEandACCESS_WIFI_STATE. For standalone binaries without an Android context, usedefault-features = falseand enablegatewayas needed. - On macOS, Xcode targets that perform the final link may need to link
SystemConfiguration.framework. On macOS and iOS, the native byte counters wrap at 4 GiB. - On illumos, traffic counters, gateway addresses, and DNS servers are unavailable. The default-interface helper can still identify the interface by its source address.
This crate was originally published as default-net
and was later rebranded to netdev by the author for future expansion, clearer naming, and long-term maintenance.