MCPcopy Index your code
hub / github.com/RustPython/RustPython / IPv4Network

Class IPv4Network

Lib/ipaddress.py:1483–1562  ·  view source on GitHub ↗

This class represents and manipulates 32-bit IPv4 network + addresses.. Attributes: [examples for IPv4Network('192.0.2.0/27')] .network_address: IPv4Address('192.0.2.0') .hostmask: IPv4Address('0.0.0.31') .broadcast_address: IPv4Address('192.0.2.32') .netmask: IP

Source from the content-addressed store, hash-verified

1481
1482
1483class IPv4Network(_BaseV4, _BaseNetwork):
1484
1485 """This class represents and manipulates 32-bit IPv4 network + addresses..
1486
1487 Attributes: [examples for IPv4Network('192.0.2.0/27')]
1488 .network_address: IPv4Address('192.0.2.0')
1489 .hostmask: IPv4Address('0.0.0.31')
1490 .broadcast_address: IPv4Address('192.0.2.32')
1491 .netmask: IPv4Address('255.255.255.224')
1492 .prefixlen: 27
1493
1494 """
1495 # Class to use when creating address objects
1496 _address_class = IPv4Address
1497
1498 def __init__(self, address, strict=True):
1499 """Instantiate a new IPv4 network object.
1500
1501 Args:
1502 address: A string or integer representing the IP [& network].
1503 '192.0.2.0/24'
1504 '192.0.2.0/255.255.255.0'
1505 '192.0.2.0/0.0.0.255'
1506 are all functionally the same in IPv4. Similarly,
1507 '192.0.2.1'
1508 '192.0.2.1/255.255.255.255'
1509 '192.0.2.1/32'
1510 are also functionally equivalent. That is to say, failing to
1511 provide a subnetmask will create an object with a mask of /32.
1512
1513 If the mask (portion after the / in the argument) is given in
1514 dotted quad form, it is treated as a netmask if it starts with a
1515 non-zero field (e.g. /255.0.0.0 == /8) and as a hostmask if it
1516 starts with a zero field (e.g. 0.255.255.255 == /8), with the
1517 single exception of an all-zero mask which is treated as a
1518 netmask == /0. If no mask is given, a default of /32 is used.
1519
1520 Additionally, an integer can be passed, so
1521 IPv4Network('192.0.2.1') == IPv4Network(3221225985)
1522 or, more generally
1523 IPv4Interface(int(IPv4Interface('192.0.2.1'))) ==
1524 IPv4Interface('192.0.2.1')
1525
1526 Raises:
1527 AddressValueError: If ipaddress isn't a valid IPv4 address.
1528 NetmaskValueError: If the netmask isn't valid for
1529 an IPv4 address.
1530 ValueError: If strict is True and a network address is not
1531 supplied.
1532 """
1533 addr, mask = self._split_addr_prefix(address)
1534
1535 self.network_address = IPv4Address(addr)
1536 self.netmask, self._prefixlen = self._make_netmask(mask)
1537 packed = int(self.network_address)
1538 if packed & int(self.netmask) != packed:
1539 if strict:
1540 raise ValueError('%s has host bits set' % self)

Callers 4

ip_networkFunction · 0.85
__init__Method · 0.85
is_globalMethod · 0.85
_IPv4ConstantsClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected