Package ZenUtils :: Module IpUtil
[hide private]
[frames] | no frames]

Module IpUtil

source code

Classes [hide private]
  IpAddressError
  InvalidIPRangeError
Attempted to parse an invalid IP range.
Functions [hide private]
 
checkip(ip)
check that an ip is valid
source code
 
numbip(ip)
convert a string ip to number
source code
 
ipFromIpMask(ipmask)
get just the ip from an ip mask pair like 1.1.1.1/24
source code
 
strip(ip)
convert a number ip to a string
source code
 
hexToBits(hex)
convert hex number (0xff000000 of netbits to numeric netmask (8)
source code
 
hexToMask(hex)
converts a netmask represented in hex to octets represented in decimal.
source code
 
maskToBits(netmask)
convert string rep of netmask to number of bits
source code
 
bitsToMaskNumb(netbits)
convert integer number of netbits to string netmask
source code
 
bitsToMask(netbits) source code
 
getnet(ip, netmask)
get network address of ip as string netmask is in form 255.255.255.0
source code
 
getnetstr(ip, netmask)
return network number as string
source code
 
asyncNameLookup(address, uselibcresolver=True) source code
 
asyncIpLookup(name)
Look up an IP based on the name passed in.
source code
 
parse_iprange(iprange)
Turn a string specifying an IP range into a list of IPs.
source code
Variables [hide private]
  __doc__ = """U...
  isip = re.compile("^\d+\.\d+\.\d+\.\d+$").search
return match if this is an ip.
  _masks = 0x000000ffL, 0x0000ff00L, 0x00ff0000L, 0xff000000L,
Function Details [hide private]

hexToMask(hex)

source code 
converts a netmask represented in hex to octets represented in decimal. e.g. "0xffffff00" -> "255.255.255.0"

asyncIpLookup(name)

source code 

Look up an IP based on the name passed in. We use gethostbyname to make sure that we use /etc/hosts as mentioned above.

This hasn't been tested.

parse_iprange(iprange)

source code 
Turn a string specifying an IP range into a list of IPs.
Parameters:
  • iprange (str
    >>> parse_iprange('10.0.0.1-5')
    ['10.0.0.1', '10.0.0.2', '10.0.0.3', '10.0.0.4', '10.0.0.5']
    >>> parse_iprange('10.0.0.1')
    ['10.0.0.1']
    >>> try: parse_iprange('10.0.0.1-2-3')
    ... except InvalidIPRangeError: print "Invalid"
    Invalid
    ) - The range string, in the format '10.0.0.a-b'

Variables Details [hide private]

__doc__

Value:
"""Util

Utility functions for the Confmon Product

"""