Connection Utilities¶
Connection and networking based utility functions. This will likely be expanded later to have all of arm’s functions, but for now just moving the parts we need.
is_valid_ipv4_address - checks if a string is a valid IPv4 address
is_valid_ipv6_address - checks if a string is a valid IPv6 address
is_valid_port - checks if something is a valid representation for a port
expand_ipv6_address - provides an IPv6 address with its collapsed portions expanded
get_mask_ipv4 - provides the mask representation for a given number of bits
get_mask_ipv6 - provides the IPv6 mask representation for a given number of bits
- stem.util.connection.is_valid_ipv4_address(address)[source]¶
Checks if a string is a valid IPv4 address.
Parameters: address (str) – string to be checked Returns: True if input is a valid IPv4 address, False otherwise
- stem.util.connection.is_valid_ipv6_address(address, allow_brackets=False)[source]¶
Checks if a string is a valid IPv6 address.
Parameters: - address (str) – string to be checked
- allow_brackets (bool) – ignore brackets which form ‘[address]’
Returns: True if input is a valid IPv6 address, False otherwise
- stem.util.connection.is_valid_port(entry, allow_zero=False)[source]¶
Checks if a string or int is a valid port number.
Parameters: - entry (list,str,int) – string, integer or list to be checked
- allow_zero (bool) – accept port number of zero (reserved by definition)
Returns: True if input is an integer and within the valid port range, False otherwise
- stem.util.connection.expand_ipv6_address(address)[source]¶
Expands abbreviated IPv6 addresses to their full colon separated hex format. For instance...
>>> expand_ipv6_address("2001:db8::ff00:42:8329") "2001:0db8:0000:0000:0000:ff00:0042:8329" >>> expand_ipv6_address("::") "0000:0000:0000:0000:0000:0000:0000:0000"
Parameters: address (str) – IPv6 address to be expanded Raises : ValueError if the address can’t be expanded due to being malformed
- stem.util.connection.get_mask_ipv4(bits)[source]¶
Provides the IPv4 mask for a given number of bits, in the dotted-quad format.
Parameters: bits (int) – number of bits to be converted Returns: str with the subnet mask representation for this many bits Raises : ValueError if given a number of bits outside the range of 0-32
- stem.util.connection.get_mask_ipv6(bits)[source]¶
Provides the IPv6 mask for a given number of bits, in the hex colon-delimited format.
Parameters: bits (int) – number of bits to be converted Returns: str with the subnet mask representation for this many bits Raises : ValueError if given a number of bits outside the range of 0-128