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
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))
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"))
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"))