Get local network interface addresses using only proc?

Posted by Matt Joiner on Stack Overflow See other posts from Stack Overflow or by Matt Joiner
Published on 2011-03-12T07:42:19Z Indexed on 2011/03/12 8:10 UTC
Read the original article Hit count: 203

Filed under:
|
|
|
|

How can I obtain the (IPv4) addresses for all network interfaces using only proc? After some extensive investigation I've discovered the following:

  1. ifconfig makes use of SIOCGIFADDR, which requires open sockets and advance knowledge of all the interface names. It also isn't documented in any manual pages on Linux.
  2. proc contains /proc/net/dev, but this is a list of interface statistics.
  3. proc contains /proc/net/if_inet6, which is exactly what I need but for IPv6.
  4. Generally interfaces are easy to find in proc, but actual addresses are very rarely used except where explicitly part of some connection.
  5. There's a system call called getifaddrs, which is very much a "magical" function you'd expect to see in Windows. It's also implemented on BSD. However it's not very text-oriented, which makes it difficult to use from non-C languages.

© Stack Overflow or respective owner

Related posts about python

Related posts about linux