§
P&Ÿ4¾žÊã ó¢ — d Z dZddlZdZdZ G d„ de¦ « Z G d„ d e¦ « Zd
„ Zd3d„Z d
„ Z
d„ Zd„ Zd„ Z
d„ Zd„ Zd„ Zd„ Zd„ Zd„ Z G d„ d¦ « Zdaej G d„ de¦ « ¦ « Zej G d„ de¦ « ¦ « Z G d„ d¦ « Zee_ G d„ d ¦ « Z G d!„ d"ee¦ « Z G d#„ d$e¦ « Z G d%„ d&ee¦ « Z G d'„ d(¦ « Zee_ ee_ G d)„ d*¦ « Z G d+„ d,e e¦ « Z! G d-„ d.e!¦ « Z" G d/„ d0e e¦ « Z# G d1„ d2¦ « Z$e$e!_ e$e#_ dS )4z•A fast, lightweight IPv4/IPv6 manipulation library in Python.
This library is used to create/poke/manipulate IPv4 and IPv6 addresses
and networks.
z1.0é Né é€ c ó — e Zd ZdZdS )ÚAddressValueErrorz%A Value Error related to the address.N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó ú6/opt/alt/python-internal/lib64/python3.11/ipaddress.pyr r ó € € € € € Ø/Ð/Ð/Ð/r
r c ó — e Zd ZdZdS )ÚNetmaskValueErrorz%A Value Error related to the netmask.Nr r r
r r r r r
r c ó — t | ¦ « S # t t f$ r Y nw xY w t | ¦ « S # t t f$ r Y nw xY wt | ›d�¦ « ‚)a® Take an IP string/int and return an object of the correct type.
Args:
address: A string or integer, the IP address. Either IPv4 or
IPv6 addresses may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.
Returns:
An IPv4Address or IPv6Address object.
Raises:
ValueError: if the *address* passed isn't either a v4 or a v6
address
z. does not appear to be an IPv4 or IPv6 address)ÚIPv4Addressr r ÚIPv6AddressÚ
ValueError©Úaddresss r Ú
ip_addressr s� € ð
ݘ7Ñ#Ô#Ð#øÝÕ0Ð1ð
ð
ð
؈ð
øøøð
ݘ7Ñ#Ô#Ð#øÝÕ0Ð1ð
ð
ð
؈ð
øøøõ ˜ÐQÐQÐQÑ
RÔ
RÐRó ‚ ‘%¤%©8 ¸AÁATc óÆ — t | |¦ « S # t t f$ r Y nw xY w t | |¦ « S # t t f$ r Y nw xY wt | ›d�¦ « ‚)aÐ Take an IP string/int and return an object of the correct type.
Args:
address: A string or integer, the IP network. Either IPv4 or
IPv6 networks may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.
Returns:
An IPv4Network or IPv6Network object.
Raises:
ValueError: if the string passed isn't either a v4 or a v6
address. Or if the network has host bits set.
z. does not appear to be an IPv4 or IPv6 network)ÚIPv4Networkr r ÚIPv6Networkr )r Ústricts r Ú
ip_networkr 9 s‘ € ð
ݘ7 FÑ+Ô+Ð+øÝÕ0Ð1ð
ð
ð
؈ð
øøøð
ݘ7 FÑ+Ô+Ð+øÝÕ0Ð1ð
ð
ð
؈ð
øøøõ ˜ÐQÐQÐQÑ
RÔ
RÐRs ‚ ’&¥&ª: ºAÁ
Ac ó — t | ¦ « S # t t f$ r Y nw xY w t | ¦ « S # t t f$ r Y nw xY wt | ›d�¦ « ‚)ag Take an IP string/int and return an object of the correct type.
Args:
address: A string or integer, the IP address. Either IPv4 or
IPv6 addresses may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.
Returns:
An IPv4Interface or IPv6Interface object.
Raises:
ValueError: if the string passed isn't either a v4 or a v6
address.
Notes:
The IPv?Interface classes describe an Address on a particular
Network, so they're basically a combination of both the Address
and Network classes.
z0 does not appear to be an IPv4 or IPv6 interface)Ú
IPv4Interfacer r Ú
IPv6Interfacer r s r Úip_interfacer" V s� € ð*
ݘWÑ%Ô%Ð%øÝÕ0Ð1ð
ð
ð
؈ð
øøøð
ݘWÑ%Ô%Ð%øÝÕ0Ð1ð
ð
ð
؈ð
øøøõ ˜ÐSÐSÐSÑ
TÔ
TÐTr c óh — | d¦ « S # t $ r t d¦ « ‚w xY w)a` Represent an address as 4 packed bytes in network (big-endian) order.
Args:
address: An integer representation of an IPv4 IP address.
Returns:
The integer address packed as 4 bytes in network (big-endian) order.
Raises:
ValueError: If the integer is negative or too large to be an
IPv4 IP address.
é z&Address negative or too large for IPv4©Úto_bytesÚ
OverflowErrorr r s r Úv4_int_to_packedr( x sJ € ðCØ×Ò Ñ"Ô"Ð"øÝð Cð Cð CÝÐAÑBÔBÐBðCøøøó ‚ —1c óh — | d¦ « S # t $ r t d¦ « ‚w xY w)zõRepresent an address as 16 packed bytes in network (big-endian) order.
Args:
address: An integer representation of an IPv6 IP address.
Returns:
The integer address packed as 16 bytes in network (big-endian) order.
é z&Address negative or too large for IPv6r% r s r Úv6_int_to_packedr, Œ sJ € ðCØ×Ò Ñ#Ô#Ð#øÝð Cð Cð CÝÐAÑBÔBÐBðCøøør) c ó” — t | ¦ « d¦ « }t |¦ « dk rt d| ›�¦ « ‚|S )zAHelper to split the netmask and raise AddressValueError if neededú/é zOnly one '/' permitted in )ÚstrÚsplitÚlenr )r Úaddrs r Ú_split_optional_netmaskr4 œ sF € åˆw‰<Œ<×Ò˜cÑ"Ô"€DÝ
ˆ4�y„y�1‚}€}ÝÐ H¸WÐ HÐ HÑIÔIÐIØ€Kr
c # óš K — t | ¦ « }t |¦ « x}}|D ]}|j |j dz k r||fV — |}|}Œ ||fV — dS )zÏFind a sequence of sorted deduplicated IPv#Address.
Args:
addresses: a list of IPv#Address objects.
Yields:
A tuple containing the first and last IP addresses in the sequence.
é N)ÚiterÚnextÚ_ip)Ú addressesÚitÚfirstÚlastÚips r Ú_find_address_ranger? ¤ sw è è € õ
ˆi‰Œ€Bݘ‘8”8ЀEˆDØð ð ˆØ
Œ6�T”X ‘\Ò!Ð!ؘ�+ÐÐÐØˆE؈ˆØ
�ˆ+ÐÐÐÐÐr
c ód — | dk r|S t || | dz
z ¦ « ¦ « S )zåCount the number of zero bits on the right hand side.
Args:
number: an integer.
bits: maximum number of bits to count.
Returns:
The number of zero bits on the right hand side of the number.
r r6 )ÚminÚ
bit_length)ÚnumberÚbitss r Ú_count_righthand_zero_bitsrE ¸ s9 € ð �‚{€{؈݈t�v�g ¨¡Ñ*×6Ò6Ñ8Ô8Ñ9Ô9Ð9r
c # ój K — t | t ¦ « rt |t ¦ « st d¦ « ‚| j |j k rt | ›d|›d�¦ « ‚| |k rt d¦ « ‚| j dk rt
}n"| j dk rt }nt d¦ « ‚| j }| j }|j }||k rmt t ||¦ « ||z
dz ¦ « dz
¦ « } ||||z
f¦ « }|V — |d|z z
}|dz
|j k rd S ||k °kd S d S )
a¤ Summarize a network range given the first and last IP addresses.
Example:
>>> list(summarize_address_range(IPv4Address('192.0.2.0'),
... IPv4Address('192.0.2.130')))
... #doctest: +NORMALIZE_WHITESPACE
[IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/31'),
IPv4Network('192.0.2.130/32')]
Args:
first: the first IPv4Address or IPv6Address in the range.
last: the last IPv4Address or IPv6Address in the range.
Returns:
An iterator of the summarized IPv(4|6) network objects.
Raise:
TypeError:
If the first and last objects are not IP addresses.
If the first and last objects are not the same version.
ValueError:
If the last object is not greater than the first.
If the version of the first address is not 4 or 6.
z1first and last must be IP addresses, not networksú and ú are not of the same versionz*last IP address must be greater than firstr$ é zunknown IP versionr6 N)
Ú
isinstanceÚ_BaseAddressÚ TypeErrorÚversionr r r Ú_max_prefixlenr9 rA rE rB Ú _ALL_ONES)r<