3 _Vjú/ ã @ s„ d Z dZddlZdZdZG dd„ deƒZG dd „ d eƒZd d„ Zd=d d„Z dd„ Z dd„ Zdd„ Zdd„ Z dd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ ZG d#d$„ d$ƒZejG d%d&„ d&eƒƒZejG d'd(„ d(eƒƒZG d)d*„ d*ƒZG d+d,„ d,eeƒZG d-d.„ d.eƒZG d/d0„ d0eeƒZG d1d2„ d2ƒZee_G d3d4„ d4ƒZG d5d6„ d6eeƒZG d7d8„ d8eƒZ G d9d:„ d:eeƒZ!G d;d<„ d<ƒZ"e"e_dS )>z•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 @ s e Zd ZdZdS )ÚAddressValueErrorz%A Value Error related to the address.N)Ú__name__Ú __module__Ú__qualname__Ú__doc__© r r ú!/usr/lib64/python3.6/ipaddress.pyr s r c @ s e Zd ZdZdS )ÚNetmaskValueErrorz%A Value Error related to the netmask.N)r r r r r r r r r s r c C sT yt | ƒS ttfk r Y nX yt| ƒS ttfk rB Y nX td| ƒ‚dS )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 z0%r does not appear to be an IPv4 or IPv6 addressN)ÚIPv4Addressr r ÚIPv6AddressÚ ValueError)Úaddressr r r Ú ip_address s r Tc C sX y t | |ƒS ttfk r" Y nX y t| |ƒS ttfk rF Y nX td| ƒ‚dS )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. z0%r does not appear to be an IPv4 or IPv6 networkN)ÚIPv4Networkr r ÚIPv6Networkr )r Ústrictr r r Ú ip_network9 s r c C sT yt | ƒS ttfk r Y nX yt| ƒS ttfk rB Y nX td| ƒ‚dS )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. z2%r does not appear to be an IPv4 or IPv6 interfaceN)Ú IPv4Interfacer r Ú IPv6Interfacer )r r r r Úip_interfaceW s r c C s. y| j ddƒS tk r( tdƒ‚Y nX dS )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. é Úbigz&Address negative or too large for IPv4N)Úto_bytesÚ OverflowErrorr )r r r r Úv4_int_to_packedz s r c C s. y| j ddƒS tk r( tdƒ‚Y nX dS )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. é r z&Address negative or too large for IPv6N)r r r )r r r r Úv6_int_to_packedŽ s r c C s* t | ƒjdƒ}t|ƒdkr&td| ƒ‚|S )zAHelper to split the netmask and raise AddressValueError if neededú/é zOnly one '/' permitted in %r)ÚstrÚsplitÚlenr )r Úaddrr r r Ú_split_optional_netmaskž s r% c c sR t | ƒ}t|ƒ }}x.|D ]&}|j|jd kr<||fV |}|}qW ||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Úipr r r Ú_find_address_range¦ s r/ c C s$ | dkr|S t || | d @ jƒ ƒ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 r&