Home | Trees | Index | Help |
---|
Module supernetting |
|
supernetting.py merges a list of subnets to remove subnets which are a part of a greater (least specific) subnet.
The script can used to get a smaller routing tables or a smaller firewall rule set.
The algorithm is detailed described in mergeSubnets
and sumSubnets
.
- SunOS 5.8; Python 2.2.1 - Linux 2.6.11 on x86; Python 2.3.5Revision History:
$Log: supernetting-module.html,v $ Revision 1.1 2005-05-21 10:35:18 carsten - Dokumentation zu supernetting.py erstellt mit epydoc Revision 1.3 2005/05/19 18:39:04 carsten - version 1.0 - rename some function to get a more readable name - use internal functions to converts ip addresses between dotted quad and integer numbers - enhance and correct documentation - add option --test to allow a simple function test - run pychecker and fix a lof of messages Revision 1.2 2005/04/17 10:20:21 carsten - version 1.0rc1 - enhance documentation - add command line options - add a detailed usage message - small improvements Revision 1.1 2005/02/20 11:17:38 carsten - initial import to CVS - script merge subnets (supernetting)
Version: see __version__
Author: Carsten Grohmann <mail (at) carstengrohmann (dot) de>
License: GPL version 2.0 or above
Note: You can use the same functionality in perl with the NetAddr-IP module from http://search.cpan.org/dist/NetAddr-IP/
To Do: add support for iana styled ip addresses
Function Summary | |
---|---|
Convert a long integer IP address to dotted quad IP address | |
Convert a dotted quad IP address in long integer | |
Prints an error message to stderr and leave the script | |
Transforms a subnet with a decimal IP into a subnet with a dotted quad IP | |
Return the netmask from the subnet | |
Returns a decimal IP address from a subnetmask with a decimal IP inside | |
Returns the IP address from a subnet | |
Returns the network address. | |
Prints a information | |
Checks if the subnet mask a valid dotted quad IP address with a subnet mask in CIDR style | |
main loop - get and check the command line options and runs the functions | |
Merge subnets (Supernetting) | |
Clear all bits of the host part in a subnet address dotted quad style | |
Summarise a list of subnets. | |
Runs some tests to check the correct work of different functions | |
Print usage message and exit | |
Prints a warn message |
Variable Summary | |
---|---|
str |
__author__ : author of this script and his email address |
str |
__copyright__ : copyright and licence string |
str |
__date__ : date of the last changes |
str |
__revision__ : internal revision number |
str |
__version__ : version number of this script |
dict |
lowest_bit : dictionary with the lowest bit of a netmask; it will used to get
faster access and better readability of the source code |
dict |
mask_hex : used for fast translations beetween CIDR styled subnetmasks and normal
styled subnet masks |
int |
verbose : switch to enable or disable additional informations about the merging
and reducing of the subnets; see also info |
Function Details |
---|
decimalToDottedQuad(number)Convert a long integer IP address to dotted quad IP address
|
dottedQuadToDecimal(ipaddress)Convert a dotted quad IP address in long integer
|
error(message='', returnvalue=1)Prints an error message to stderr and leave the script The message will print out with "ERROR:" as prefix
|
formatSubnet(subnet)Transforms a subnet with a decimal IP into a subnet with a dotted quad IP
|
getCIDRNetmask(subnet)Return the netmask from the subnet
|
getDecimalIP(subnet)Returns a decimal IP address from a subnetmask with a decimal IP inside
|
getIP(subnet)Returns the IP address from a subnet
|
getNetworkAddress(subnet, netmask=0)Returns the network address. This function have two imput formats:
|
info(message='')Prints a information The message will print out with "INFO:" as prefix.
|
isCIDRSubnet(subnet)Checks if the subnet mask a valid dotted quad IP address with a subnet mask in CIDR style
|
main()main loop - get and check the command line options and runs the functions |
mergeSubnets(subnetlist)Merge subnets (Supernetting) A even networkaddress and the following odd networkaddress with the same netmask can merge to the even networkaddress with a networkmask reduced by 1 bit. This smaller (least specific) subnet contains both parent subnets. Example: The subnets 4.0.0.0/8 and 5.0.0.0/8 can reduce to 4.0.0.0/7. The function checks also if subnets are parts of other subnets and
reduces the unnecessary subnet entry. See You get smaller routing or firewall tables thru this both steps. It is possible to optimize this function to get more speed. To optimize it, change the handling of the odd right bit of the subnetmask.
|
normSubnet(subnet)Clear all bits of the host part in a subnet address dotted quad style
|
sumSubnets(subnetlist)Summarise a list of subnets. Remove all subnet, which are a member of smaller subnet
|
test()Runs some tests to check the correct work of different functions |
usage(rval=0)Print usage message and exit
|
warning(message='')Prints a warn message The message will print out with "WARNING:" as prefix.
|
Variable Details |
---|
__author__author of this script and his email address
|
__copyright__copyright and licence string
|
__date__date of the last changes
|
__revision__internal revision number
|
__version__version number of this script
|
mask_hexused for fast translations beetween CIDR styled subnetmasks and normal styled subnet masks
|
verboseswitch to enable or disable additional informations about the merging and reducing of the subnets; see alsoinfo
|
Home | Trees | Index | Help |
---|
Generated by Epydoc 2.1 on Thu May 19 20:42:10 2005 | http://epydoc.sf.net |