equal
deleted
inserted
replaced
7 |
7 |
8 Network/IP address related class and function |
8 Network/IP address related class and function |
9 """ |
9 """ |
10 |
10 |
11 import socket |
11 import socket |
|
12 |
|
13 from binascii import b2a_hex |
12 |
14 |
13 |
15 |
14 class NetInfo(object): |
16 class NetInfo(object): |
15 """Simple class for CIDR network addresses an IP addresses.""" |
17 """Simple class for CIDR network addresses an IP addresses.""" |
16 __slots__ = ('_addr', '_prefix', '_bits_max', '_family', '_nw_addr') |
18 __slots__ = ('_addr', '_prefix', '_bits_max', '_family', '_nw_addr') |
95 family = socket.AF_INET6 |
97 family = socket.AF_INET6 |
96 try: |
98 try: |
97 address = socket.inet_pton(family, ip_address) |
99 address = socket.inet_pton(family, ip_address) |
98 except socket.error: |
100 except socket.error: |
99 raise ValueError('Not a valid IPv6 address: %r' % ip_address) |
101 raise ValueError('Not a valid IPv6 address: %r' % ip_address) |
100 return (family, int(address.encode('hex'), 16)) |
102 return (family, int(b2a_hex(address), 16)) |