iplib module (daxfi package).
The representations of an IPv4 address and a netmask.
You can use this module to convert amongst many different IP notations.
This module is part of the IPConv program, that you can find here:
http://digilander.iol.it/alberanid/soft/
Copyright 2001, 2002 Davide Alberani <alberanid@libero.it>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Imported modules
|
|
import re
import string
import types
|
Functions
|
|
|
|
_bin_to_dec
|
_bin_to_dec ( ip )
Binary to decimal convesion.
Exceptions
|
|
ValueError, '_bin_to_dec: ip not valid'
|
|
|
_dec_to_bin
|
_dec_to_bin ( ip )
Decimal to binary conversion.
Exceptions
|
|
ValueError, '_dec_to_bin: ip not valid'
|
|
|
_dec_to_dec
|
_dec_to_dec ( ip )
Decimal to decimal conversion.
Exceptions
|
|
ValueError, '_dec_to_dec: ip not valid'
|
|
|
_dec_to_dot
|
_dec_to_dot ( ip )
Decimal to dotted decimal notation convesion.
Exceptions
|
|
ValueError, '_dec_to_dot: ip not valid'
|
|
|
_dec_to_dot_nm
|
_dec_to_dot_nm ( nm )
Decimal to dotted decimal notation conversion.
|
|
_dec_to_hex
|
_dec_to_hex ( ip )
Decimal to hexadecimal convesion.
Exceptions
|
|
ValueError, '_dec_to_hex: ip not valid'
|
|
|
_dec_to_oct
|
_dec_to_oct ( ip )
Decimal to octal convesion.
Exceptions
|
|
ValueError, '_dec_to_oct: ip not valid'
|
|
|
_dot_to_dec
|
_dot_to_dec ( ip )
Dotted decimal notation to decimal conversion.
Exceptions
|
|
ValueError, '_dot_to_dec: ip not valid'
|
|
|
_dot_to_dec_nm
|
_dot_to_dec_nm ( nm )
Dotted decimal to decimal notation conversion.
|
|
_hex_to_dec
|
_hex_to_dec ( ip )
Hexadecimal to decimal conversion.
Exceptions
|
|
ValueError, '_hex_to_dec: ip not valid'
|
|
|
_oct_to_dec
|
_oct_to_dec ( ip )
Octal to decimal conversion.
Exceptions
|
|
ValueError, '_oct_to_dec: ip not valid'
|
|
|
convert
|
convert (
ip,
notation=IP_DOT,
iformat=IP_UNKNOWN,
)
Convert among ip notations.
Given an ip address, this functions returns the ip in another
notation.
- ip
The ip address.
- notation
The format of the output.
- iformat
Force the input to be considered of the given type
(otherwise it's autodetected).
Exceptions
|
|
ValueError, 'convert: if the ip is given in a numeric' + ' format, you must specify it with the "iformat"' + ' parameter'
ValueError, 'convert: unknown ip format: "' + str( kind ) + '"'
ValueError, 'convert: unknown notation: "' + str( notation ) + '"'
|
|
|
convert_nm
|
convert_nm (
nm,
notation=NM_DOT,
iformat=NM_UNKNOWN,
)
Convert among netmask notations.
Given a netmask, this functions returns the netmask in another
notation.
- nm
The netmask.
- notation
The format of the output.
Exceptions
|
|
ValueError, 'convert_nm: unknown notation: "' + str( notation ) + '"'
|
|
|
detect
|
detect ( ip )
Return the kind of an Internet address.
Given an ip, returns the kind of the notation (one of
IP_DOT, IP_HEX, IP_BIN, IP_DEC, IP_UNKNOWN).
|
|
detect_nm
|
detect_nm ( nm )
Return the kind of the netmask.
Given a netmask, returns the kind of notation (one of
NM_DOT, NM_DEC, NM_BIN, NM_UNKNOWN).
|
|
is_bin
|
is_bin ( ip )
Return true if the address is in binary notation.
Exceptions
|
|
ValueError, 'is_bin: the ip must be a string'
|
|
|
is_bin_nm
|
is_bin_nm ( nm )
Return true if the netmask is in binary notatation.
|
|
is_dec
|
is_dec ( ip )
Return true if the address is in decimal notation.
Exceptions
|
|
ValueError, 'is_dec: the ip must be a string'
|
|
|
is_dec_nm
|
is_dec_nm ( nm )
Return true if the netmask is in decimal notatation.
|
|
is_dot
|
is_dot ( ip )
Return true if the address is in dotted decimal notation.
Exceptions
|
|
ValueError, 'is_dot: the ip must be a string'
|
|
|
is_dot_nm
|
is_dot_nm ( nm )
Return true if the netmask is in dotted decimal notatation.
Exceptions
|
|
ValueError, 'is_dot_nm: not a valid netmask'
|
|
|
is_hex
|
is_hex ( ip )
Return true if the address is in hexadecimal notation.
Exceptions
|
|
ValueError, 'is_hex: the ip must be a string'
|
|
|
is_oct
|
is_oct ( ip )
Return true if the address is in octal notation.
Exceptions
|
|
ValueError, 'is_oct: the ip must be a string'
|
|
|
p_detect
|
p_detect ( ip )
Return the kind of an Internet address (string).
Given an ip, returns a string that represents the kind of notation.
|
|
p_detect_nm
|
p_detect_nm ( nm )
Return the kind of the netmask (string).
Given a netmask, returns a string that represents the
notation.
|
Classes
|
|
|
|