def test_reverse_address(self): s = '1.2.3.4' expected = '4.3.2.1.in-addr.arpa' self.assertEqual(pycares.reverse_address(s), expected) s = '2607:f8b0:4010:801::1013' expected = '3.1.0.1.0.0.0.0.0.0.0.0.0.0.0.0.1.0.8.0.0.1.0.4.0.b.8.f.7.0.6.2.ip6.arpa' self.assertEqual(pycares.reverse_address(s), expected)
def test_query_ptr(self): def cb(result, errorno): self.assertEqual(errorno, None) ip = '173.194.69.102' self.channel.query(pycares.reverse_address(ip), pycares.QUERY_TYPE_PTR, cb) self.wait()
def query_ip(self,ip): if ip not in self.rlookup_history: try: hostnames = yield from self.resolver.query(pycares.reverse_address(ip),"PTR") except aiodns.error.DNSError: hostnames = [] self.rlookup_history[ip] = hostnames return self.rlookup_history[ip]
def reverse_address(ip_address): """Returns the reversed representation of an IP address, usually used when doing PTR queries. :param str ip_address: IP address to be reversed :rtype: str """ return pycares.reverse_address(ip_address)
def test_query_ptr_ipv6(self): self.result, self.errorno = None, None def cb(result, errorno): self.result, self.errorno = result, errorno ip = '2001:4860:4860::8888' self.channel.query(pycares.reverse_address(ip), pycares.QUERY_TYPE_PTR, cb) self.wait() self.assertEqual(type(self.result), pycares.ares_query_ptr_result) self.assertEqual(self.errorno, None)
async def _do_lookup(self, ip): """ Internal. Perform a reverse DNS lookup for an IP returning the IP (or None) and the TTL of the DNS entry. """ try: result = await self.resolver.query(pycares.reverse_address(ip), "PTR") return (result.name, datetime.datetime.now() + datetime.timedelta(seconds=result.ttl)) except aiodns.error.DNSError: return (None, datetime.datetime.now())
def test_query_ptr(self): self.result, self.errorno = None, None def cb(result, errorno): self.result, self.errorno = result, errorno ip = '8.8.8.8' self.channel.query(pycares.reverse_address(ip), pycares.QUERY_TYPE_PTR, cb) self.wait() self.assertEqual(type(self.result), pycares.ares_query_ptr_result) self.assertEqual(self.errorno, None) self.assertGreater(self.result.ttl, 0) self.assertEqual(type(self.result.aliases), list)
def test_query_ptr_ipv6(self): self.result, self.errorno = None, None def cb(result, errorno): self.result, self.errorno = result, errorno ip = '2001:4860:4860::8888' self.channel.query(pycares.reverse_address(ip), pycares.QUERY_TYPE_PTR, cb) self.wait() self.assertEqual(type(self.result), pycares.ares_query_ptr_result) self.assertEqual(self.errorno, None) self.assertIsInstance(self.result.ttl, int) self.assertGreaterEqual(self.result.ttl, 0) self.assertLessEqual(self.result.ttl, 2**31 - 1) self.assertEqual(type(self.result.aliases), list)
def test_query_ptr_ipv6(self): def cb(result, errorno): self.assertEqual(errorno, None) ip = '2001:4860:4860::8888' self.channel.query(pycares.reverse_address(ip), pycares.QUERY_TYPE_PTR, cb) self.wait()
def test_query_ptr(self): ip = '8.8.8.8' f = self.resolver.query(pycares.reverse_address(ip), 'PTR') result = self.loop.run_until_complete(f) self.assertTrue(result)
def test_reverse_address(self): s = '1.2.3.4' expected = '4.3.2.1.in-addr.arpa' self.assertEqual(pycares.reverse_address(s), expected)
def test_query_ptr(self): ip = '173.194.69.102' result = self.resolver.query(pycares.reverse_address(ip), 'PTR') self.assertTrue(result)
def ptr(self, ipaddress: str, callback=None): self._query(pycares.reverse_address(ipaddress), ipaddress, pycares.QUERY_TYPE_PTR, 'PTR%', callback)