;ň Żb/?c@sXdZdZdkZdkZd„Zd„Zd„Zd„Zd„Zd„Z dS( s ipadr.py - handling of IP addresses (c) by Michael Stroeder This module is distributed under the terms of the GPL (GNU GENERAL PUBLIC LICENSE) Version 2 (see http://www.gnu.org/copyleft/gpl.html) $Id: ipadr.py,v 1.15 2003/08/05 07:54:23 michael Exp $ s0.1.1NcCs'tidti|iƒƒƒdSdS(sC Convert string representation of IP address to 32-bit integer s!IiN(sstructsunpackssockets inet_atonsAddrStrsstrip(sAddrStr((s./pylib/ipadr.pysAddr2IntscCstitid|ƒƒSdS(sC Convert string representation of IP address to 32-bit integer s!IN(ssockets inet_ntoasstructspacksAddrInt(sAddrInt((s./pylib/ipadr.pysInt2AddrscCsUy|iddƒ\}}Wntj otd‚nXt|ƒt|ƒfSdS(sV Convert network address/mask string representation to tuple of 32-bit integers s/is0Argument must have the form 'ip address/netmask'N(s AddrMaskStrssplitsAddrStrsMaskStrs ValueErrorsAddr2Int(s AddrMaskStrsMaskStrsAddrStr((s./pylib/ipadr.pysAddrMask_Str2Tuples cCs+dit|dƒt|dƒfƒSdS(sU Convert network address/mask tuple (32-bit integers) to string representation s/iiN(sjoinsInt2Addrs addrMaskTuple(s addrMaskTuple((s./pylib/ipadr.pysAddrMask_Tuple2Str*scCs.t|ƒ}|\}}||@||@jSdS(s? Check if IP address is within of a network address range. N(sAddr2IntsAddrStrsAddrIntsNetAddrMaskTuplesNetAddrsNetMask(sAddrStrsNetAddrMaskTuplesAddrIntsNetAddrsNetMask((s./pylib/ipadr.pys MatchIPAddr2s  cCsTd}t|ƒ}x1||jot|||ƒ o|d}qW||jSdS(sŒ return 1 (true) if any (Addr,Mask) in AddrMaskTupleList is matched by IP address given in AddrStr return 0 (false) if none matches iiN(sislensAddrMaskTupleListsListLens MatchIPAddrsAddrStr(sAddrStrsAddrMaskTupleListsListLensi((s./pylib/ipadr.pysMatchIPAdrList;s "( s__doc__s __version__ssocketsstructsAddr2IntsInt2AddrsAddrMask_Str2TuplesAddrMask_Tuple2Strs MatchIPAddrsMatchIPAdrList( ssocketsAddrMask_Str2Tuples MatchIPAddrsAddrMask_Tuple2StrsInt2Addrs __version__sAddr2IntsMatchIPAdrListsstruct((s./pylib/ipadr.pys? s