Example #1
0
def get_address_type(address, resolve=False):
    if is_ipv4_address(address):
        return ADDR_IPV4
    if is_ipv6_address(address):
        return ADDR_IPV6
    if resolve:
        try:
            socket.getaddrinfo(address, None)
        except socket.gaierror:
            return ADDR_UNRESOLVABLE
    return ADDR_FQDN
Example #2
0
def get_address_type(address, resolve=False):
    if is_ipv4_address(address):
        return ADDR_IPV4
    if is_ipv6_address(address):
        return ADDR_IPV6
    if resolve:
        try:
            socket.getaddrinfo(address, None)
        except socket.gaierror:
            return ADDR_UNRESOLVABLE
    return ADDR_FQDN
Example #3
0
 def test_bad(self):
     self.assertFalse(validate.is_ipv4_address("abcd"))
     self.assertFalse(validate.is_ipv4_address("192 168 1 1"))
     self.assertFalse(validate.is_ipv4_address("3232235521"))
     self.assertFalse(validate.is_ipv4_address("::1"))
     self.assertFalse(validate.is_ipv4_address(1234))
Example #4
0
 def test_valid(self):
     self.assertTrue(validate.is_ipv4_address("192.168.1.1"))
     self.assertTrue(validate.is_ipv4_address("1.2.3.4"))
     self.assertTrue(validate.is_ipv4_address("255.255.255.255"))
     self.assertTrue(validate.is_ipv4_address("0.0.0.0"))
Example #5
0
 def test_bad(self):
     self.assertFalse(validate.is_ipv4_address("abcd"))
     self.assertFalse(validate.is_ipv4_address("192 168 1 1"))
     self.assertFalse(validate.is_ipv4_address("3232235521"))
     self.assertFalse(validate.is_ipv4_address("::1"))
Example #6
0
 def test_valid(self):
     self.assertTrue(validate.is_ipv4_address("192.168.1.1"))
     self.assertTrue(validate.is_ipv4_address("1.2.3.4"))
     self.assertTrue(validate.is_ipv4_address("255.255.255.255"))
     self.assertTrue(validate.is_ipv4_address("0.0.0.0"))