Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to produce a list of all the interfaces available on a [Linux] system, and for each interface, produce a list of available IP addresses. I was hoping to do this in a more graceful fashion than parsing the output of the ip command while still avoiding the hassle of ioctl() and friends.

Unfortunately, while /sys/class/net/INTERFACE contains link-level addressing information (such as the interface MAC address), it does not contain any ip addressing information. Nor do any of the files in /proc contain this information.

Before I go off and make my Python code look a lot more like C, are there better tools for this? Something like ip that produces structured output would be nice.

share|improve this question
What's wrong with parsing ifconfig output? For Python I'm surprised some are writing their own getifaddrs module – Steve-o Sep 23 '11 at 18:40
First and foremost, ifconfig is actively broken. It doesn't understand multiple addresses associated with an interface, and it has the unfortunate habit of truncating long interface names. More generally, having structured access to so much information via /sys makes me wish for the same convenience here. – larsks Sep 23 '11 at 18:43
Also, I have come across a few Python modules, and many of them look suspiciously unmaintained. A system level solution would be nicely language agnostic. – larsks Sep 23 '11 at 18:53
You mean about ifconfig being broken? Try working in an environment using VLAN trunking and bonded interfaces, and watch things relying on ifconfig break because all of a sudden all of your interface names look the same. Sure, it doesn't affect home or workstation users, but it't not all that uncommon, either. – larsks Sep 23 '11 at 19:01
@Steve-o: Slight exaggeration? ifconfig is DEPRECATED. Stop recommending and using it. It is also broken in some situations as it can't properly handle things as larsks mentions. – MikeyB Sep 23 '11 at 19:21

Puppet Labs (the company that makes Puppet) also makes a tool called Facter:

Facter is a lightweight program that gathers basic node information about the hardware and operating system. Facter is especially useful for retrieving things like operating system names, hardware characteristics, IP addresses, MAC addresses, and SSH keys.

It does not require Puppet to be installed or used, just a Ruby interpreter.

I find Facter to be incredibly useful in my day-to-day sysadmin tasks for just this sort of reason. For instance, to show the IP address(es) on a box:

$ facter interfaces
$ facter | grep ipaddress
ipaddress =>
ipaddress_eth0 =>
ipaddress_eth0_0 =>
$ facter ipaddress_eth0

There are lots of other pieces of information Facter can provide, and it's easy to write your own custom facts to extend it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.