This class represents and manipulates 128-bit IPv6 networks. Attributes: [examples for IPv6('2001:db8::1000/124')] .network_address: IPv6Address('2001:db8::1000') .hostmask: IPv6Address('::f') .broadcast_address: IPv6Address('2001:db8::100f') .netmask: IPv6Addres
| 2276 | |
| 2277 | |
| 2278 | class IPv6Network(_BaseV6, _BaseNetwork): |
| 2279 | |
| 2280 | """This class represents and manipulates 128-bit IPv6 networks. |
| 2281 | |
| 2282 | Attributes: [examples for IPv6('2001:db8::1000/124')] |
| 2283 | .network_address: IPv6Address('2001:db8::1000') |
| 2284 | .hostmask: IPv6Address('::f') |
| 2285 | .broadcast_address: IPv6Address('2001:db8::100f') |
| 2286 | .netmask: IPv6Address('ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0') |
| 2287 | .prefixlen: 124 |
| 2288 | |
| 2289 | """ |
| 2290 | |
| 2291 | # Class to use when creating address objects |
| 2292 | _address_class = IPv6Address |
| 2293 | |
| 2294 | def __init__(self, address, strict=True): |
| 2295 | """Instantiate a new IPv6 Network object. |
| 2296 | |
| 2297 | Args: |
| 2298 | address: A string or integer representing the IPv6 network or the |
| 2299 | IP and prefix/netmask. |
| 2300 | '2001:db8::/128' |
| 2301 | '2001:db8:0000:0000:0000:0000:0000:0000/128' |
| 2302 | '2001:db8::' |
| 2303 | are all functionally the same in IPv6. That is to say, |
| 2304 | failing to provide a subnetmask will create an object with |
| 2305 | a mask of /128. |
| 2306 | |
| 2307 | Additionally, an integer can be passed, so |
| 2308 | IPv6Network('2001:db8::') == |
| 2309 | IPv6Network(42540766411282592856903984951653826560) |
| 2310 | or, more generally |
| 2311 | IPv6Network(int(IPv6Network('2001:db8::'))) == |
| 2312 | IPv6Network('2001:db8::') |
| 2313 | |
| 2314 | strict: A boolean. If true, ensure that we have been passed |
| 2315 | A true network address, eg, 2001:db8::1000/124 and not an |
| 2316 | IP address on a network, eg, 2001:db8::1/124. |
| 2317 | |
| 2318 | Raises: |
| 2319 | AddressValueError: If address isn't a valid IPv6 address. |
| 2320 | NetmaskValueError: If the netmask isn't valid for |
| 2321 | an IPv6 address. |
| 2322 | ValueError: If strict was True and a network address was not |
| 2323 | supplied. |
| 2324 | """ |
| 2325 | addr, mask = self._split_addr_prefix(address) |
| 2326 | |
| 2327 | self.network_address = IPv6Address(addr) |
| 2328 | self.netmask, self._prefixlen = self._make_netmask(mask) |
| 2329 | packed = int(self.network_address) |
| 2330 | if packed & int(self.netmask) != packed: |
| 2331 | if strict: |
| 2332 | raise ValueError('%s has host bits set' % self) |
| 2333 | else: |
| 2334 | self.network_address = IPv6Address(packed & |
| 2335 | int(self.netmask)) |
no outgoing calls
no test coverage detected
searching dependent graphs…