Get the ipv6 address from a interface

Kai Timmer email at kait.de
Thu Apr 9 04:36:17 EDT 2009


Hello,
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(
      s.fileno(),
      0x8915,  # SIOCGIFADDR
      struct.pack('256s', ifname[:15])
  )[20:24])

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.

Greets,
Kai



More information about the Python-list mailing list