Another solution using only stdlib:
import socket import struct def int_from_ipv6(addr): hi, lo = struct.unpack('!QQ', socket.inet_pton(socket.AF_INET6, addr)) return (hi << 64) | lo
Example
>>> int_from_ipv6('fe80::fbd6:7860') 338288524927261089654018896845572831328L
In Python 3.3+, you can use the ipaddress module :
>>> import ipaddress >>> int(ipaddress.ip_address('fe80::fbd6:7860')) 338288524927261089654018896845572831328
jfs
source share