def testIsIp(self): from Exscript.util.ipv4 import is_ip self.assert_(is_ip('0.0.0.0')) self.assert_(is_ip('255.255.255.255')) self.assert_(is_ip('1.2.3.4')) self.assert_(not is_ip('')) self.assert_(not is_ip('1')) self.assert_(not is_ip('1.2.3.')) self.assert_(not is_ip('.1.2.3')) self.assert_(not is_ip('1.23.4')) self.assert_(not is_ip('1..3.4'))
def is_ip(string): """ Returns True if the given string is an IPv4 or IPv6 address, False otherwise. :type string: string :param string: Any string. :rtype: bool :return: True if the string is an IP address, False otherwise. """ return ipv4.is_ip(string) or ipv6.is_ip(string)
def is_ip(string): """ Returns True if the given string is an IPv4 or IPv6 address, False otherwise. @type string: string @param string: Any string. @rtype: bool @return: True if the string is an IP address, False otherwise. """ return ipv4.is_ip(string) or ipv6.is_ip(string)
def set_address(self, address): """ Set the address of the remote host the is contacted, without changing hostname, username, password, protocol, and TCP port number. This is the actual address that is used to open the connection. @type address: string @param address: A hostname or IP name. """ if is_ip(address): self.address = clean_ip(address) else: self.address = address
def _is_ip(string): # Adds IPv6 support. return ':' in string or is_ip(string)
def _call_func(funcname, ip, *args): if ipv4.is_ip(ip): return ipv4.__dict__[funcname](ip, *args) elif ipv6.is_ip(ip): return ipv6.__dict__[funcname](ip, *args) raise ValueError('neither ipv4 nor ipv6: ' + repr(ip))