IPv4Obj Object

class ccp_util.IPv4Obj(arg='127.0.0.1/32', strict=False)

An object to represent IPv4 addresses and IPv4Networks. When IPv4Obj objects are compared or sorted, shorter masks are greater than longer masks. After comparing mask length, numerically higher IP addresses are greater than numerically lower IP addresses.

Kwargs:
  • arg (str): A string containing an IPv4 address, and optionally a netmask or masklength. The following address/netmask formats are supported: “10.1.1.1/24”, “10.1.1.1 255.255.255.0”, “10.1.1.1/255.255.255.0”
Attributes:
  • network_object : An IPv4Network object
  • ip_object : An IPv4Address object
  • ip : An IPv4Address object
  • as_binary_tuple (tuple): The address as a tuple of zero-padded binary strings
  • as_hex_tuple (tuple): The address as a tuple of zero-padded 8-bit hex strings
  • as_decimal (int): The ip address as a decimal integer
  • network (str): A string representing the network address
  • netmask (str): A string representing the netmask
  • prefixlen (int): An integer representing the length of the netmask
  • broadcast (str): A string representing the broadcast address
  • hostmask (str): A string representing the hostmask
  • numhosts (int): An integer representing the number of hosts contained in the network
Returns:
as_binary_tuple

Returns the IP address as a tuple of zero-padded binary strings

as_decimal

Returns the IP address as a decimal integer

as_hex_tuple

Returns the IP address as a tuple of zero-padded hex strings

broadcast

Returns the broadcast address as an IPv4Address object.

hostmask

Returns the host mask as an IPv4Address object.

ip

Returns the address as an IPv4Address object.

is_multicast

Returns a boolean for whether this is a multicast address

is_private

Returns a boolean for whether this is a private address

is_reserved

Returns a boolean for whether this is a reserved address

netmask

Returns the network mask as an IPv4Address object.

network

Returns an IPv4Network object, which represents this network.

numhosts

Returns the total number of IP addresses in this network, including broadcast and the “subnet zero” address

prefixlen

Returns the length of the network mask as an integer.

version

Returns the version of the object as an integer. i.e. 4