0

I'm interested in enumerating all local ipv4 and ipv6 addresses on a system.

The solution needs to be pure python (without shelling out).

Ideally it's portable (Linux, OSX, Windows) but I doubt that's possible, so an answer for each platform would work, too...

sneak
  • 1,068
  • 1
  • 12
  • 16
  • This is similar to http://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib but that only lists the first address, and only v4. I need all of them, including v6. – sneak Jun 16 '12 at 08:26

1 Answers1

2

There's no portable way to do that.

On Linux, you may use fcntl.ioctl with op=SIOCGIFCONF (which is defined as 0x8912).

If you're open to use a library, take a look at netifaces. It does exactly what you need, and supports Linux, Mac, Solaris, and Windows. This answer might give you and idea.

Community
  • 1
  • 1
jweyrich
  • 31,198
  • 5
  • 66
  • 97