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.
ifconfigoutput? For Python I'm surprised some are writing their own getifaddrs module – Steve-o Sep 23 '11 at 18:40ifconfigis 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/sysmakes me wish for the same convenience here. – larsks Sep 23 '11 at 18:43ifconfigis 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