Package netaddr :: Package strategy :: Module ipv4
[hide private]
[frames] | no frames]

Module ipv4

IPv4 address logic.

Functions [hide private]
 
valid_str(addr, flags=0)
Returns: True if IPv4 address is valid, False otherwise.
 
str_to_int(addr, flags=0)
Returns: The equivalent unsigned integer for a given IPv4 address.
 
int_to_str(int_val, dialect=None)
Returns: The IPv4 presentation (string) format address equivalent to the unsigned integer provided.
 
int_to_arpa(int_val)
Returns: The reverse DNS lookup for an IPv4 address in network byte order integer form.
 
int_to_packed(int_val)
Returns: a packed string that is equivalent to value represented by an unsigned integer.
 
packed_to_int(packed_int)
Returns: An unsigned integer equivalent to value of network address represented by packed binary string.
 
valid_words(words)
 
int_to_words(int_val)
Returns: An integer word (octet) sequence that is equivalent to value represented by an unsigned integer.
 
words_to_int(words)
Returns: An unsigned integer that is equivalent to value represented by word (octet) sequence.
 
valid_bits(bits)
 
bits_to_int(bits)
 
int_to_bits(int_val, word_sep=None)
 
valid_bin(bin_val)
 
int_to_bin(int_val)
 
bin_to_int(bin_val)
 
expand_partial_address(addr)
Expands a partial IPv4 address into a full 4-octet version.
Variables [hide private]
  width = 32
  word_size = 8
  word_fmt = '%d'
  word_sep = '.'
  family = 2
  family_name = 'IPv4'
  version = 4
  word_base = 10
  max_int = 4294967295
  num_words = 4
  max_word = 255
  prefix_to_netmask = {0: 0, 1: 2147483648, 2: 3221225472, 3: 37...
  netmask_to_prefix = {0: 0, 2147483648: 1, 3221225472: 2, 37580...
  prefix_to_hostmask = {0: 4294967295, 1: 2147483647, 2: 1073741...
  hostmask_to_prefix = {0: 32, 1: 31, 3: 30, 7: 29, 15: 28, 31: ...
  __package__ = 'netaddr.strategy'
  i = 32
Function Details [hide private]

valid_str(addr, flags=0)

 
Parameters:
  • addr - An IPv4 address in presentation (string) format.
  • flags - decides which rules are applied to the interpretation of the addr value. Supported constants are INET_PTON and ZEROFILL. See the netaddr.core docs for details.
Returns:
True if IPv4 address is valid, False otherwise.

str_to_int(addr, flags=0)

 
Parameters:
  • addr - An IPv4 dotted decimal address in string form.
  • flags - decides which rules are applied to the interpretation of the addr value. Supported constants are INET_PTON and ZEROFILL. See the netaddr.core docs for details.
Returns:
The equivalent unsigned integer for a given IPv4 address.

int_to_str(int_val, dialect=None)

 
Parameters:
  • int_val - An unsigned integer.
  • dialect - (unused) Any value passed in is ignored.
Returns:
The IPv4 presentation (string) format address equivalent to the unsigned integer provided.

int_to_arpa(int_val)

 
Parameters:
  • int_val - An unsigned integer.
Returns:
The reverse DNS lookup for an IPv4 address in network byte order integer form.

int_to_packed(int_val)

 
Parameters:
  • int_val - the integer to be packed.
Returns:
a packed string that is equivalent to value represented by an unsigned integer.

packed_to_int(packed_int)

 
Parameters:
  • packed_int - a packed string containing an unsigned integer. It is assumed that string is packed in network byte order.
Returns:
An unsigned integer equivalent to value of network address represented by packed binary string.

int_to_words(int_val)

 
Parameters:
  • int_val - An unsigned integer.
Returns:
An integer word (octet) sequence that is equivalent to value represented by an unsigned integer.

words_to_int(words)

 
Parameters:
  • words - A list or tuple containing integer octets.
Returns:
An unsigned integer that is equivalent to value represented by word (octet) sequence.

expand_partial_address(addr)

 

Expands a partial IPv4 address into a full 4-octet version.

Parameters:
  • addr - an partial or abbreviated IPv4 address
Returns:
an expanded IP address in presentation format (x.x.x.x)

Variables Details [hide private]

prefix_to_netmask

Value:
{0: 0,
 1: 2147483648,
 2: 3221225472,
 3: 3758096384,
 4: 4026531840,
 5: 4160749568,
 6: 4227858432,
 7: 4261412864,
...

netmask_to_prefix

Value:
{0: 0,
 2147483648: 1,
 3221225472: 2,
 3758096384: 3,
 4026531840: 4,
 4160749568: 5,
 4227858432: 6,
 4261412864: 7,
...

prefix_to_hostmask

Value:
{0: 4294967295,
 1: 2147483647,
 2: 1073741823,
 3: 536870911,
 4: 268435455,
 5: 134217727,
 6: 67108863,
 7: 33554431,
...

hostmask_to_prefix

Value:
{0: 32,
 1: 31,
 3: 30,
 7: 29,
 15: 28,
 31: 27,
 63: 26,
 127: 25,
...