Exemple #1
0
    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)
Exemple #2
0
    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)
Exemple #3
0
    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()
Exemple #4
0
 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]
Exemple #5
0
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)
Exemple #6
0
 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)
Exemple #7
0
 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)
Exemple #8
0
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)
 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())
Exemple #10
0
    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)
Exemple #11
0
    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)
Exemple #12
0
 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()
Exemple #13
0
 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()
Exemple #14
0
 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)
Exemple #15
0
 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)
Exemple #16
0
 def test_query_ptr(self):
     ip = '173.194.69.102'
     result = self.resolver.query(pycares.reverse_address(ip), 'PTR')
     self.assertTrue(result)
Exemple #17
0
 def ptr(self, ipaddress: str, callback=None):
     self._query(pycares.reverse_address(ipaddress), ipaddress,
                 pycares.QUERY_TYPE_PTR, 'PTR%', callback)
Exemple #18
0
 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)
Exemple #19
0
 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)