I would like to get the list of all active network interfaces (e.g. eth0, wlan0). I assume I'll have to parse the output of ifconfig, but the formatting is different across the various OS's. Does anybody have a portable way to get this information so it can be used on the majority of unices (linux, *bsd, mac).
|
feedback
|
|
Not sure about portabilty because a list of network interfaces may be related to the kernel implementation and linux is not related at all to *bsd/mac... however if ifconfig is not good for you you can try | |||
|
feedback
|
|
Check out the facter package. It is used mostly by the puppet config management program to grab metadata from installed machines, but it can be run in a standalone fashion for similar purposes. Its output does include information about network interfaces found on the machine, and its formatting will be consistent across platforms. Example output:
| |||
|
feedback
|
|
The following will return a list of active interfaces on all the common Linux distros:
If you want to also include interfaces which are currently down (inactive), simply add the -a flag as follows:
As far as I know, there is no common method which can be used on any POSIX system to retrieve a list of network interfaces, so you'll have to localize your command for the OS currently in use. | |||
|
feedback
|
|
Netstat -i and ifconfig will only show you the currently "active" network interfaces. An active interface can also have no carrier and thus be unusable. You need to look for the RUNNING flag (ifconfig), or R flag (netstat -i). This flag denotes that the interface has an active carrier, or most commonly is has something the network interface is physically connected to such as a switch. | |||
|
feedback
|