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

Function ip_address

Lib/ipaddress.py:25–51  ·  view source on GitHub ↗

Take an IP string/int and return an object of the correct type. Args: address: A string or integer, the IP address. Either IPv4 or IPv6 addresses may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns: An IPv4Address

(address)

Source from the content-addressed store, hash-verified

23
24
25def ip_address(address):
26 """Take an IP string/int and return an object of the correct type.
27
28 Args:
29 address: A string or integer, the IP address. Either IPv4 or
30 IPv6 addresses may be supplied; integers less than 2**32 will
31 be considered to be IPv4 by default.
32
33 Returns:
34 An IPv4Address or IPv6Address object.
35
36 Raises:
37 ValueError: if the *address* passed isn't either a v4 or a v6
38 address
39
40 """
41 try:
42 return IPv4Address(address)
43 except (AddressValueError, NetmaskValueError):
44 pass
45
46 try:
47 return IPv6Address(address)
48 except (AddressValueError, NetmaskValueError):
49 pass
50
51 raise ValueError(f'{address!r} does not appear to be an IPv4 or IPv6 address')
52
53
54def ip_network(address, strict=True):

Callers

nothing calls this directly

Calls 2

IPv4AddressClass · 0.85
IPv6AddressClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…