Package DebTorrent :: Module subnetparse
[hide private]
[frames] | no frames]

Module subnetparse

source code

Deal with all types of IP addresses and IP address subnets.

Classes [hide private]
  IP_List
Stores multiple IP address subnets.
Functions [hide private]
string
to_bitfield_ipv4(ip)
Convert an IPv4 address to it's binary string representation.
source code
string
to_bitfield_ipv6(ip)
Convert an IPv6 address to it's binary string representation.
source code
string
ipv6_to_ipv4(ip)
Convert an IPv6 address in the transition format to an IPv4 address.
source code
boolean
to_ipv4(ip)
Determine whether the IP address is in the IPv4 format.
source code
boolean
is_ipv4(ip)
Determine whether the IP address is in the IPv4 format.
source code
 
_valid_ipv4(ip)
Determine whether the IP address is a valid IPv4 address.
source code
boolean
is_valid_ip(ip)
Determine whether the IP address is a valid IPv4 or IPv6 address.
source code
Variables [hide private]
logging.Logger logger = logging.getLogger('DebTorrent.subnetparse')
the logger to send all log messages to for this module
dictionary hexbinmap = {'0': '0000', '1': '0001', '2': '0010', '3': '0011...
mapping from the hex characters to their binary string representation
dictionary chrbinmap = {0: '00000000', 1: '00000001', 2: '00000010', 3: '...
mapping from the first 256 numbers to their binary string representation
long ipv4addrmask = '0000000000000000000000000000000000000000000000...
the address mask used to determine if the IP address in long format is v4 encapsulated in a v6 address
  b = ['1', '1', '1', '1', '1', '1', '1', '1']
  i = 7
  n = 255
  nn = 65280

Imports: bisect.bisect, bisect.insort, logging


Function Details [hide private]

to_bitfield_ipv4(ip)

source code 
Convert an IPv4 address to it's binary string representation.
Parameters:
  • ip (string) - the IPv4 address to convert
Returns: string
the binary string of the IPv4 address

to_bitfield_ipv6(ip)

source code 
Convert an IPv6 address to it's binary string representation.
Parameters:
  • ip (string) - the IPv6 address to convert
Returns: string
the binary string of the IPv6 address

ipv6_to_ipv4(ip)

source code 
Convert an IPv6 address in the transition format to an IPv4 address.
Parameters:
  • ip (string) - the IP address to convert
Returns: string
the IPv4 address

to_ipv4(ip)

source code 
Determine whether the IP address is in the IPv4 format.
Parameters:
  • ip (string) - the IP address to check
Returns: boolean
whether the IP address is for IPv4

is_ipv4(ip)

source code 
Determine whether the IP address is in the IPv4 format.
Parameters:
  • ip (string) - the IP address to check
Returns: boolean
whether the IP address is for IPv4

_valid_ipv4(ip)

source code 
Determine whether the IP address is a valid IPv4 address.
Parameters:
  • ip (string) - the IP address to check
Raises:
  • ValueError - if the address is not in the proper IPv4 format

is_valid_ip(ip)

source code 
Determine whether the IP address is a valid IPv4 or IPv6 address.
Parameters:
  • ip (string) - the IP address to check
Returns: boolean
whether the IP address is valid

Variables Details [hide private]

hexbinmap

mapping from the hex characters to their binary string representation
Type:
dictionary
Value:
{'0': '0000',
 '1': '0001',
 '2': '0010',
 '3': '0011',
 '4': '0100',
 '5': '0101',
 '6': '0110',
 '7': '0111',
...

chrbinmap

mapping from the first 256 numbers to their binary string representation
Type:
dictionary
Value:
{0: '00000000',
 1: '00000001',
 2: '00000010',
 3: '00000011',
 4: '00000100',
 5: '00000101',
 6: '00000110',
 7: '00000111',
...

ipv4addrmask

the address mask used to determine if the IP address in long format is v4 encapsulated in a v6 address
Type:
long
Value:
'000000000000000000000000000000000000000000000000000000000000000000000\
000000000001111111111111111'