MCPcopy Index your code
hub / github.com/python/cpython / IPv4Address

Class IPv4Address

Lib/ipaddress.py:1263–1410  ·  view source on GitHub ↗

Represent and manipulate single IPv4 Addresses.

Source from the content-addressed store, hash-verified

1261 return '.'.join(reverse_octets) + '.in-addr.arpa'
1262
1263class IPv4Address(_BaseV4, _BaseAddress):
1264
1265 """Represent and manipulate single IPv4 Addresses."""
1266
1267 __slots__ = ('_ip', '__weakref__')
1268
1269 def __init__(self, address):
1270
1271 """
1272 Args:
1273 address: A string or integer representing the IP
1274
1275 Additionally, an integer can be passed, so
1276 IPv4Address('192.0.2.1') == IPv4Address(3221225985).
1277 or, more generally
1278 IPv4Address(int(IPv4Address('192.0.2.1'))) ==
1279 IPv4Address('192.0.2.1')
1280
1281 Raises:
1282 AddressValueError: If ipaddress isn't a valid IPv4 address.
1283
1284 """
1285 # Efficient constructor from integer.
1286 if isinstance(address, int):
1287 self._check_int_address(address)
1288 self._ip = address
1289 return
1290
1291 # Constructing from a packed address
1292 if isinstance(address, bytes):
1293 self._check_packed_address(address, 4)
1294 self._ip = int.from_bytes(address) # big endian
1295 return
1296
1297 # Assume input argument to be string or any object representation
1298 # which converts into a formatted IP string.
1299 addr_str = str(address)
1300 if '/' in addr_str:
1301 raise AddressValueError(f"Unexpected '/' in {address!r}")
1302 self._ip = self._ip_int_from_string(addr_str)
1303
1304 @property
1305 def packed(self):
1306 """The binary representation of this address."""
1307 return v4_int_to_packed(self._ip)
1308
1309 @property
1310 def is_reserved(self):
1311 """Test if the address is otherwise IETF reserved.
1312
1313 Returns:
1314 A boolean, True if the address is within the
1315 reserved IPv4 Network range.
1316
1317 """
1318 return self in self._constants._reserved_network
1319
1320 @property

Callers 10

ip_addressFunction · 0.85
_make_netmaskMethod · 0.85
ipMethod · 0.85
__init__Method · 0.85
_IPv4ConstantsClass · 0.85
_ip_int_from_stringMethod · 0.85
ipv4_mappedMethod · 0.85
teredoMethod · 0.85
sixtofourMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…