ipaddresstools package

Submodules

ipaddresstools.ipaddresstools module

Script Name: ipaddresstools.py Script Type: Python Updated By: Benjamin P. Trachtenberg Date Written 1/11/2015

Description: Collection of tools for IP Address’s

ipaddresstools.ipaddresstools.all_ip_address_in_subnet(ip_net, cidr)[source]

Function to return every ip in a subnet

Parameters:
  • ip_net (String) – String format 192.168.1.1
  • cidr (String) – CIDR value of 0 to 32
Return type:

List

Returns:

A List of IPv4 Address’s

ipaddresstools.ipaddresstools.all_subnets_longer_prefix(ip_net, cidr)[source]

Function to return every subnet a ip can belong to with a longer prefix

Parameters:
  • ip_net (String) – String format 192.168.1.1
  • cidr (String) – CIDR value of 0 to 32
Return type:

List

Returns:

A List of subnets

ipaddresstools.ipaddresstools.all_subnets_possible(ip_net, cidr)[source]

Function to return every subnet a ip can belong to with a longer prefix

Parameters:
  • ip_net (String) – String format 192.168.1.1
  • cidr (String) – CIDR value of 0 to 32
Return type:

List

Returns:

A List of subnets

ipaddresstools.ipaddresstools.all_subnets_shorter_prefix(ip_net, cidr, include_default=False)[source]

Function to return every subnet a ip can belong to with a shorter prefix

Parameters:
  • ip_net (String) – String format 192.168.1.1
  • cidr (String) – CIDR value of 0 to 32
  • include_default (Boolean) – True or False
Return type:

List

Returns:

A List of subnets

ipaddresstools.ipaddresstools.cidr_check(cidr, return_cidr=True)[source]

Function to verify a good CIDR value

Parameters:
  • cidr (Integer) – 30
  • return_cidr (Boolean) – True or False
Return type:

String

Returns:

String

ipaddresstools.ipaddresstools.get_neighbor_ip(ip_addr, cidr='30')[source]

Function to figure out the IP’s between neighbors address

Parameters:
  • ip_addr (String) – String format 192.168.1.1
  • cidr (String) – CIDR value of 30, or 31
Return type:

Tuple

Returns:

returns Our IP and the Neighbor IP in a tuple

ipaddresstools.ipaddresstools.ip(ip_addr, return_tuple=True)[source]

Function to check if a address is good

Parameters:
  • ip_addr (String) – String format 192.168.1.1
  • return_tuple (Boolean) – True or False
Return type:

Tuple, or Boolean

Returns:

Tuple, or Boolean

ipaddresstools.ipaddresstools.ip_mask(ip_addr_and_mask, return_tuple=True)[source]

Function to check if a address and CIDR mask is good

Parameters:
  • ip_addr_and_mask (String) – String format 192.168.1.1/24
  • return_tuple (Boolean) – True or False
Return type:

Tuple, or Boolean

Returns:

Tuple, or Boolean

ipaddresstools.ipaddresstools.mcast_ip(ip_addr, return_tuple=True)[source]

Function to check if a address is multicast

Parameters:
  • ip_addr (String) – String format 239.1.1.1
  • return_tuple (Boolean) – True or False
Return type:

Tuple, or Boolean

Returns:

Tuple, or Boolean

ipaddresstools.ipaddresstools.mcast_ip_mask(ip_addr_and_mask, return_tuple=True)[source]

Function to check if a address is multicast and that the CIDR mask is good

Parameters:
  • ip_addr_and_mask (String) – String format 239.0.0.0/24
  • return_tuple (Boolean) – True or False
Return type:

Tuple, or Boolean

Returns:

Tuple, or Boolean

ipaddresstools.ipaddresstools.number_check(check, return_number=True)[source]

Function to verify item entered is a number

Parameters:
  • check (Anything) – What to check
  • return_number (Boolean) – True or False
Return type:

Boolean

Returns:

Check return_number for return options

ipaddresstools.ipaddresstools.random_cidr_mask(lowest_mask=16)[source]

Function to generate a random CIDR value

Parameters:lowest_mask (Integer) – An integer value for the lowest mask you want it to generate
Return type:String
Returns:A string of a random CIDR mask
ipaddresstools.ipaddresstools.random_mcast_ip()[source]

Function to generate a random multicast ip address

Return type:String
Returns:A multicast IP Address
ipaddresstools.ipaddresstools.random_mcast_ip_mask(lowest_mask=16)[source]

Function to generate a random multicast ip address and cidr mask pair in the following format X.X.X.X/X

Parameters:lowest_mask (Integer) – An integer value for the lowest mask you want it to generate
Return type:String
Returns:A multicast IP Address and CIDR pair in the following format X.X.X.X/X
ipaddresstools.ipaddresstools.random_ucast_ip()[source]

Function to generate a random unicast ip address

Return type:String
Returns:A unicast IP Address
ipaddresstools.ipaddresstools.random_ucast_ip_mask(lowest_mask=16)[source]

Function to generate a random unicast ip address and cidr mask pair in the following format X.X.X.X/X

Parameters:lowest_mask (Integer) – An integer value for the lowest mask you want it to generate
Return type:String
Returns:A unicast IP Address and CIDR pair in the following format X.X.X.X/X
ipaddresstools.ipaddresstools.subnet_range(ip_net, cidr)[source]

Function to return a subnet range value from a IP address and CIDR pair

Parameters:
  • ip_net (String) – String format 192.168.1.1
  • cidr (String) – CIDR value of 1 to 32
Return type:

Dict

Returns:

returns a dictionary of info

ipaddresstools.ipaddresstools.ucast_ip(ip_addr, return_tuple=True)[source]

Function to check if a address is unicast

Parameters:
  • ip_addr (String) – String format 192.168.1.1
  • return_tuple (Boolean) – True or False
Return type:

Tuple, or Boolean

Returns:

Tuple, or Boolean

ipaddresstools.ipaddresstools.ucast_ip_mask(ip_addr_and_mask, return_tuple=True)[source]

Function to check if a address is unicast and that the CIDR mask is good

Parameters:
  • ip_addr_and_mask (String) – String format 192.168.1.1/24
  • return_tuple (Boolean) – True or False
Return type:

Tuple, or Boolean

Returns:

Tuple, or Boolean

ipaddresstools.ipaddresstools.whole_subnet_maker(ip_addr, cidr)[source]

Function to return a whole subnet value from a IP address and CIDR pair

Parameters:
  • ip_addr (String) – String format 192.168.1.1
  • cidr (String) – CIDR value of 0 to 32
Return type:

String

Returns:

returns the corrected whole subnet

Module contents

Init for ipaddresstools