feature request: wireless capable method for NetworkInterface
I would like to be able to find wireless network adapters with this crate (as opposed to wired), and find out the network adapter name and mac address.
Hey @uglyoldbob! Thanks for reaching out!
network-interface lists already wireless networks such as WiFi, for instance in MacOS you can do:
networksetup -listallhardwareports
Which prints a list of hardware devices:
Hardware Port: Ethernet Adapter (en4)
Device: en4
Ethernet Address: <>
Hardware Port: Ethernet Adapter (en5)
Device: en5
Ethernet Address: <>
Hardware Port: Ethernet Adapter (en6)
Device: en6
Ethernet Address: <>
Hardware Port: Thunderbolt Bridge
Device: bridge0
Ethernet Address: <>
Hardware Port: Wi-Fi
Device: en0
Ethernet Address: <>
Hardware Port: Thunderbolt 1
Device: en1
Ethernet Address: <>
Here you can see that en0 is a WiFi interface, then you can see it as a NetworkInterface in the output.
About extra details on the NetworkInterface such as MACAddress we had added support to it before on Unix systems here: https://github.com/LeoBorai/network-interface/pull/28/files
Its available as a field: https://docs.rs/network-interface/2.0.1/network_interface/struct.NetworkInterface.html#structfield.mac_addr
Perhaps you are using a different OS so you always see None?
I do see the mac address, but I don't see anything that identifies if a particular network interface is wireless or not.
I run the following code snippet
let network_interfaces = network_interface::NetworkInterface::show().unwrap();
for v in &network_interfaces {
log::error!("The network interface is {:?}", v);
}
And these are the results I get from that.
2025-05-22T15:12:19.127Z ERROR [radio_service] The network interface is NetworkInterface { name: "docker0", addr: [V4(V4IfAddr { ip: 172.17.0.1, broadcast: Some(172.17.255.255), netmask: Some(255.255.0.0) })], mac_addr: Some("02:42:eb:40:87:95"), index: 4 }
2025-05-22T15:12:19.127Z ERROR [radio_service] The network interface is NetworkInterface { name: "lo", addr: [V4(V4IfAddr { ip: 127.0.0.1, broadcast: Some(127.0.0.1), netmask: Some(255.0.0.0) }), V6(V6IfAddr { ip: ::1, broadcast: None, netmask: Some(ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff) })], mac_addr: Some("00:00:00:00:00:00"), index: 1 }
2025-05-22T15:12:19.127Z ERROR [radio_service] The network interface is NetworkInterface { name: "wlp0s20f3", addr: [V4(V4IfAddr { ip: 192.168.16.223, broadcast: Some(192.168.19.255), netmask: Some(255.255.252.0) }), V6(V6IfAddr { ip: fe80::e6dd:2336:7b30:58d0, broadcast: None, netmask: Some(ffff:ffff:ffff:ffff::) })], mac_addr: Some("00:93:37:ef:b7:53"), index: 3 }
2025-05-22T15:12:19.127Z ERROR [radio_service] The network interface is NetworkInterface { name: "tap0", addr: [V4(V4IfAddr { ip: 192.168.7.1, broadcast: Some(192.168.7.255), netmask: Some(255.255.255.255) }), V6(V6IfAddr { ip: fe80::446a:dbff:fe24:3488, broadcast: None, netmask: Some(ffff:ffff:ffff:ffff::) })], mac_addr: Some("46:6a:db:24:34:88"), index: 14 }
2025-05-22T15:12:19.127Z ERROR [radio_service] The network interface is NetworkInterface { name: "enp3s0", addr: [V4(V4IfAddr { ip: 10.128.128.101, broadcast: Some(10.128.128.255), netmask: Some(255.255.255.0) }), V6(V6IfAddr { ip: fe80::96f5:cd43:e06d:a005, broadcast: None, netmask: Some(ffff:ffff:ffff:ffff::) })], mac_addr: Some("d4:93:90:16:37:c5"), index: 2 }
The ip addresses and mac addresses and associated settings are all there, but nothing indicating wireless or not. That is the key item I am desiring here.