This module implements the class AbstractDomain and some derived classes, which encapsulate a set of physical addresses.
The class InetDomain implements IPv4 addresses, and IP segments represented in the form A.B.C.D/M, where A.B.C.D is the network address, and M specifies the number of ones in the netmask.
from SockAddr import SockAddrInet, SockAddr, SockAddr
Module implementing SockAddr handling functions.
from socket import ntohl, htonl
from string import split, atoi
An address domain encapsulates an address type (AF_INET, AF_INET6 etc) and provides functions to parse and compare these addresses. This functionality is primarily used by Zone classes (see the module Zone), and the PacketFilter classes (see the module IPChains)
Table 4-23. Attributes for class AbstractDomain
family | address family this domain uses |
Constructor initializing an AbstractDomain instance.
__init__ ( self ) |
This constructor is basically empty and does nothing.
Table 4-24. Arguments for AbstractDomain.__init__()
self | this instance |
Function to compare two domains.
__cmp__ ( self, other ) |
This function is a placeholder and is to be overridden by derived classes. It should return -1, 0 and 1 as described in the Python documentation.
Table 4-25. Arguments for AbstractDomain.__cmp__()
self | this instance |
other | instance to compare to |
NotImplementedError
A class representing internet addresses. The inet objects are comparable, comparison means "contains", "equal to" and "contained by". The comparison can raise ValueError for incomparable ip addresses.
Table 4-26. Attributes for class InetDomain
mask_bits | number of bits in the netmask |
mask | netmask in network byte order |
ip | network addresss in network byte order |
Initializes an InetDomain instance
__init__ ( self, addr ) |
Parses the argument addr and fills in attributes accordingly.
Table 4-27. Arguments for InetDomain.__init__()
addr | the string representation of an address, or address range |
Compare this instance to another.
__cmp__ ( self, other ) |
Compare this instance to another InetDomain instance or to a SockAddrInet instance using set inclusion on addresses. An address is less than another, if it's fully contained by other.
Table 4-28. Arguments for InetDomain.__cmp__()
self | this instance |
other | the other InetDomain object to compare to |
ValueError
-1, 0, or 1
Returns the string representation of this instance.
__str__ ( self ) |
Returns the string representation of this instance in the form address/mask.
Table 4-29. Arguments for InetDomain.__str__()
self | this instance |
string
Calculate the broadcast address of this domain
broadcast ( self ) |
Return the broadcast address of this domain calculated based on attributes.
Table 4-30. Arguments for InetDomain.broadcast()
self | this instance |
the broadcast address in network byte order
Calculate the network address of this domain.
netaddr ( self ) |
Return the network address of this domain.
Table 4-31. Arguments for InetDomain.netaddr()
self | this instance |
ip address in network byte order
Calculate netmask of this domain.
netmask ( self ) |
Calculates and returns the netmask of this domain as an integer in network byte order.
Table 4-32. Arguments for InetDomain.netmask()
self | this instance |
the network mask as ip in network byte order