Network object from an IP address or hostname and mask
| 914 | |
| 915 | |
| 916 | class Net6(Net): # syntax ex. 2011:db8::/126 |
| 917 | """Network object from an IP address or hostname and mask""" |
| 918 | name = "Net6" # type: str |
| 919 | family = socket.AF_INET6 # type: int |
| 920 | max_mask = 128 # type: int |
| 921 | |
| 922 | @classmethod |
| 923 | def ip2int(cls, addr): |
| 924 | # type: (str) -> int |
| 925 | val1, val2 = struct.unpack( |
| 926 | '!QQ', inet_pton(socket.AF_INET6, cls.name2addr(addr)) |
| 927 | ) |
| 928 | return cast(int, (val1 << 64) + val2) |
| 929 | |
| 930 | @staticmethod |
| 931 | def int2ip(val): |
| 932 | # type: (int) -> str |
| 933 | return inet_ntop( |
| 934 | socket.AF_INET6, |
| 935 | struct.pack('!QQ', val >> 64, val & 0xffffffffffffffff), |
| 936 | ) |
no outgoing calls
no test coverage detected
searching dependent graphs…