Table of Contents

Module: iplib daxfi/iplib.py

iplib module.

The representations of IPv4 addresses and netmasks. You can use this module to convert amongst many different notations and to manage couples of address/netmask in the CIDR notation.

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 string
import types
Functions   
_bin_to_dec
_bits_to_dec
_check_nm
_convert
_dec_to_bin
_dec_to_bits
_dec_to_dec_long
_dec_to_dec_str
_dec_to_dot
_dec_to_hex
_dec_to_oct
_dec_to_wildcard
_detect
_dot_to_dec
_get_notation
_hex_to_dec
_is_notation
_oct_to_dec
_wildcard_to_dec
convert
convert_nm
detect
detect_nm
is_bin
is_bin_nm
is_bits_nm
is_dec
is_dec_nm
is_dot
is_dot_nm
is_hex
is_hex_nm
is_notation
is_notation_nm
is_oct
is_oct_nm
is_wildcard_nm
p_detect
p_detect_nm
  _bin_to_dec 
_bin_to_dec ( ip,  check=1 )

Binary to decimal conversion.

Exceptions   
ValueError, '_bin_to_dec: invalid IP: "' + str( ip ) + '"'
  _bits_to_dec 
_bits_to_dec ( nm,  check=1 )

Bits to decimal conversion.

Exceptions   
ValueError, '_bits_to_dec: invalid IP: "' + str( nm ) + '"'
  _check_nm 
_check_nm ( nm,  kind )

  _convert 
_convert (
        ip,
        notation,
        iformat,
        check,
        isnm,
        )

Exceptions   
ValueError, 'convert: invalid netmask: "' + str( ip ) + '"'
ValueError, 'convert: unknown IP format: "' + str( iformat_orig ) + '"'
ValueError, 'convert: unknown input format: "' + str( iformat_orig ) + '"'
ValueError, 'convert: unknown notation: "' + str( notation_orig ) + '"'
ValueError, 'convert: when the IP is given in a numeric' + ' format, you must specify it with the "iformat"' + ' parameter'
  _dec_to_bin 
_dec_to_bin ( ip )

Decimal to binary conversion.

  _dec_to_bits 
_dec_to_bits ( nm )

Decimal to bits conversion.

  _dec_to_dec_long 
_dec_to_dec_long ( ip,  check=1 )

Decimal to decimal (long) conversion.

Exceptions   
ValueError, '_dec_to_dec: invalid IP: "' + str( ip ) + '"'
  _dec_to_dec_str 
_dec_to_dec_str ( ip )

Decimal to decimal (string) conversion.

  _dec_to_dot 
_dec_to_dot ( ip )

Decimal to dotted decimal notation conversion.

  _dec_to_hex 
_dec_to_hex ( ip )

Decimal to hexadecimal conversion.

  _dec_to_oct 
_dec_to_oct ( ip )

Decimal to octal conversion.

  _dec_to_wildcard 
_dec_to_wildcard ( nm )

Decimal to wildcard bits conversion.

  _detect 
_detect ( ip,  isnm )

  _dot_to_dec 
_dot_to_dec ( ip,  check=1 )

Dotted decimal notation to decimal conversion.

Exceptions   
ValueError, '_dot_to_dec: invalid IP: "' + str( ip ) + '"'
  _get_notation 
_get_notation ( notation )

Return one value in IP_DOT, IP_HEX, IP_BIN, etc.

  _hex_to_dec 
_hex_to_dec ( ip,  check=1 )

Hexadecimal to decimal conversion.

Exceptions   
ValueError, '_hex_to_dec: invalid IP: "' + str( ip ) + '"'
  _is_notation 
_is_notation (
        ip,
        notation,
        isnm,
        )

Exceptions   
ValueError, '_is_notation: unkown notation: "' + str( notation_orig ) + '"'
  _oct_to_dec 
_oct_to_dec ( ip,  check=1 )

Octal to decimal conversion.

Exceptions   
ValueError, '_oct_to_dec: invalid IP: "' + str( ip ) + '"'
  _wildcard_to_dec 
_wildcard_to_dec ( nm,  check=0 )

Wildcard bits to decimal conversion.

Exceptions   
ValueError, '_wildcard_to_dec: invalid IP: "' + str( nm ) + '"'
  convert 
convert (
        ip,
        notation=IP_DOT,
        iformat=IP_UNKNOWN,
        check=None,
        )

Convert among IP address notations.

Given an IP address, this function returns the address in another notation.

@param ip: the IP address. @type ip: integers, strings or object with an appropriate __str()__ method.

@param notation: the notation of the output (default: IP_DOT). @type notation: one of the IP_* constants, or the equivalent strings.

@param iformat: force the input to be considered in the given notation (default the notation of the input is autodetected). @type iformat: one of the IP_* constants, or the equivalent strings.

@param check: force the notation check on the input (internally used).

@return: a string representing the IP in the selected notation.

@raise ValueError: raised when the input is in unknown notation.

  convert_nm 
convert_nm (
        nm,
        notation=IP_DOT,
        iformat=IP_UNKNOWN,
        check=None,
        )

Convert a netmask to another notation.

  detect 
detect ( ip )

Detect the notation of an IP address.

@param ip: the IP address. @type ip: integers, strings or object with an appropriate __str()__ method. @return: one of the IP_* constants; IP_UNKNOWN if undetected.

  detect_nm 
detect_nm ( nm )

Detect the notation of a netmask.

  is_bin 
is_bin ( ip )

Return true if the IP address is in binary notation.

  is_bin_nm 
is_bin_nm ( nm )

Return true if the netmask is in binary notatation.

  is_bits_nm 
is_bits_nm ( nm )

Return true if the netmask is in bits notatation.

  is_dec 
is_dec ( ip )

Return true if the IP address is in decimal notation.

  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 IP address is in dotted decimal notation.

  is_dot_nm 
is_dot_nm ( nm )

Return true if the netmask is in dotted decimal notatation.

  is_hex 
is_hex ( ip )

Return true if the IP address is in hexadecimal notation.

  is_hex_nm 
is_hex_nm ( nm )

Return true if the netmask is in hexadecimal notatation.

  is_notation 
is_notation ( ip,  notation )

Return true if the given address is in the given notation.

  is_notation_nm 
is_notation_nm ( nm,  notation )

Return true if the given netmask is in the given notation.

  is_oct 
is_oct ( ip )

Return true if the IP address is in octal notation.

  is_oct_nm 
is_oct_nm ( nm )

Return true if the netmask is in octal notatation.

  is_wildcard_nm 
is_wildcard_nm ( nm )

Return true if the netmask is in wildcard bits notatation.

  p_detect 
p_detect ( ip )

Return the notation of a IP address (string).

  p_detect_nm 
p_detect_nm ( nm )

Return the notation of the netmask (string).

Classes   
CIDR

A CIDR address.

IPv4Address

An IPv4 Internet address.

IPv4NetMask

An IPv4 Internet netmask.

_IPv4Base

Base class for IP addresses and netmasks.


Table of Contents

This document was automatically generated on Tue Dec 17 17:48:18 2002 by HappyDoc version r1_5