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

Function ip_network

Lib/ipaddress.py:54–80  ·  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 network. Either IPv4 or IPv6 networks may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns: An IPv4Network

(address, strict=True)

Source from the content-addressed store, hash-verified

52
53
54def ip_network(address, strict=True):
55 """Take an IP string/int and return an object of the correct type.
56
57 Args:
58 address: A string or integer, the IP network. Either IPv4 or
59 IPv6 networks may be supplied; integers less than 2**32 will
60 be considered to be IPv4 by default.
61
62 Returns:
63 An IPv4Network or IPv6Network object.
64
65 Raises:
66 ValueError: if the string passed isn't either a v4 or a v6
67 address. Or if the network has host bits set.
68
69 """
70 try:
71 return IPv4Network(address, strict)
72 except (AddressValueError, NetmaskValueError):
73 pass
74
75 try:
76 return IPv6Network(address, strict)
77 except (AddressValueError, NetmaskValueError):
78 pass
79
80 raise ValueError(f'{address!r} does not appear to be an IPv4 or IPv6 network')
81
82
83def ip_interface(address):

Callers

nothing calls this directly

Calls 2

IPv4NetworkClass · 0.85
IPv6NetworkClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…