Exscript.util.ipv6 module¶
IPv6 address calculation and conversion.
-
Exscript.util.ipv6.
clean_ip
(ip)[source]¶ Cleans the ip address up, useful for removing leading zeros, e.g.:
1234:0:01:02:: -> 1234:0:1:2:: 1234:0000:0000:0000:0000:0000:0000:000A -> 1234::a 1234:0000:0000:0000:0001:0000:0000:0000 -> 1234:0:0:0:1:: 0000:0000:0000:0000:0001:0000:0000:0000 -> ::1:0:0:0
Parameters: ip (string) – An IP address. Return type: string Returns: The cleaned up IP.
-
Exscript.util.ipv6.
is_ip
(string)[source]¶ Returns True if the given string is an IPv6 address, False otherwise.
Parameters: string (string) – Any string. Return type: bool Returns: True if the string is an IP address, False otherwise.
-
Exscript.util.ipv6.
normalize_ip
(ip)[source]¶ Transform the address into a standard, fixed-length form, such as:
1234:0:01:02:: -> 1234:0000:0001:0002:0000:0000:0000:0000 1234::A -> 1234:0000:0000:0000:0000:0000:0000:000aParameters: ip (string) – An IP address. Return type: string Returns: The normalized IP.
-
Exscript.util.ipv6.
parse_prefix
(prefix, default_length=128)[source]¶ Splits the given IP prefix into a network address and a prefix length. If the prefix does not have a length (i.e., it is a simple IP address), it is presumed to have the given default length.
Parameters: - prefix (string) – An IP mask.
- default_length (long) – The default ip prefix length.
Return type: string, int
Returns: A tuple containing the IP address and prefix length.