Get the ipv6 address from a interface

Kai Timmer email at
Thu Apr 9 10:36:17 CEST 2009

i need a function that returns the ipv6 address from a given interface
name. For ipv4 i use this one:
def get_ip_address(ifname):
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  return socket.inet_ntoa(fcntl.ioctl(
      0x8915,  # SIOCGIFADDR
      struct.pack('256s', ifname[:15])

which works great. But i am not enough into python to port that to
ipv6. It has to work under linux only. Any help is appreciated.


More information about the Python-list mailing list