PyDocs

Nav

Internet Protocols and Support

IPv4Network.compare_networks

ipaddress

method of IPv4Network (source) Deprecated 3.7
  • IPv4Network.compare_networks(other)
Deprecated since 3.7. It uses the same ordering and comparison algorithm as “<”, “==”, and “>”
Compare two IP objects.

This is only concerned about the comparison of the integer
representation of the network addresses.  This means that the
host bits aren't considered at all in this method.  If you want
to compare host bits, you can easily enough do a
'HostA._ip < HostB._ip'

Args:
    other: An IP object.

Returns:
    If the IP versions of self and other are the same, returns:

    -1 if self < other:
      eg: IPv4Network('192.0.2.0/25') < IPv4Network('192.0.2.128/25')
      IPv6Network('2001:db8::1000/124') <
          IPv6Network('2001:db8::2000/124')
    0 if self == other
      eg: IPv4Network('192.0.2.0/24') == IPv4Network('192.0.2.0/24')
      IPv6Network('2001:db8::1000/124') ==
          IPv6Network('2001:db8::1000/124')
    1 if self > other
      eg: IPv4Network('192.0.2.128/25') > IPv4Network('192.0.2.0/25')
          IPv6Network('2001:db8::2000/124') >
              IPv6Network('2001:db8::1000/124')

  Raises:
      TypeError if the IP versions are different.
1 Example
>>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.2/32'))
-1
>>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.0/32'))
1
>>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.1/32'))
0
from the Python docs
See Also
No see-alsos for ipaddress/IPv4Network.compare_networks
0 Notes
No notes for IPv4Network.compare_networks