Esempio n. 1
0
    def test_get_http_json(self):
        from ipwhois.rdap import RIR_RDAP
        result = Net('74.125.225.229')
        try:
            self.assertIsInstance(
                result.get_http_json(
                    RIR_RDAP['arin']['ip_url'].format('74.125.225.229')), dict)
        except HTTPLookupError:
            pass
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        self.assertRaises(HTTPLookupError, result.get_http_json,
                          **dict(url='http://255.255.255.255', retry_count=0))

        result = Net('74.125.225.229', 0)
        url = RIR_RDAP['arin']['ip_url'].format('74.125.225.229')
        self.assertRaises(HTTPLookupError, result.get_http_json,
                          **dict(url=url, retry_count=0))

        # Uncommenting below will result in a flood of up to 20 requests
        # to test rate limiting.
        '''
Esempio n. 2
0
 def test_get_whois(self):
     result = Net('74.125.225.229')
     try:
         self.assertIsInstance(result.get_whois(), str)
     except WhoisLookupError:
         pass
     except AssertionError as e:
         raise e
     except Exception as e:
         self.fail('Unexpected exception raised: %r' % e)
Esempio n. 3
0
 def test_get_host(self):
     result = Net('74.125.225.229')
     try:
         self.assertIsInstance(result.get_host(), tuple)
     except HostLookupError:
         pass
     except AssertionError as e:
         raise e
     except Exception as e:
         self.fail('Unexpected exception raised: %r' % e)
Esempio n. 4
0
 def test_get_asn_dns(self):
     data = ['"15169 ', ' 74.125.225.0/24 ', ' US ', ' arin ',
             ' 2007-03-13"']
     result = Net('74.125.225.229')
     try:
         self.assertIsInstance(result.get_asn_dns(result=data), dict)
     except AssertionError as e:
         raise e
     except Exception as e:
         self.fail('Unexpected exception raised: %r' % e)
Esempio n. 5
0
 def test_get_asn_whois(self):
     data = ('15169   | 74.125.225.229   | 74.125.225.0/24     | US | arin'
             '     | 2007-03-13')
     result = Net('74.125.225.229')
     try:
         self.assertIsInstance(result.get_asn_whois(result=data), dict)
     except AssertionError as e:
         raise e
     except Exception as e:
         self.fail('Unexpected exception raised: %r' % e)
Esempio n. 6
0
 def test_lookup_asn(self):
     result = Net('74.125.225.229')
     try:
         self.assertIsInstance(result.lookup_asn(), tuple)
     except (HTTPLookupError, ASNRegistryError):
         pass
     except AssertionError as e:
         raise e
     except Exception as e:
         self.fail('Unexpected exception raised: %r' % e)
Esempio n. 7
0
 def test_get_asn_dns(self):
     result = Net('74.125.225.229')
     try:
         self.assertIsInstance(result.get_asn_dns(), dict)
     except (ASNLookupError, ASNRegistryError):
         pass
     except AssertionError as e:
         raise e
     except Exception as e:
         self.fail('Unexpected exception raised: %r' % e)
Esempio n. 8
0
 def test_get_asn_dns(self):
     result = Net('74.125.225.229')
     try:
         self.assertIsInstance(result.get_asn_dns(), dict)
     except (ASNLookupError, ASNRegistryError):
         pass
     except AssertionError as e:
         raise e
     except Exception as e:
         self.fail('Unexpected exception raised: {0}'.format(e))
Esempio n. 9
0
 def test_get_http_json(self):
     from ipwhois.rdap import RIR_RDAP
     result = Net('74.125.225.229')
     try:
         self.assertIsInstance(result.get_http_json(
             RIR_RDAP['arin']['ip_url'].format('74.125.225.229')), dict)
     except HTTPLookupError:
         pass
     except AssertionError as e:
         raise e
     except Exception as e:
         self.fail('Unexpected exception raised: %r' % e)
Esempio n. 10
0
    def test_get_asn_whois(self):
        result = Net('74.125.225.229')
        try:
            self.assertIsInstance(result.get_asn_whois(), dict)
        except (ASNLookupError, ASNRegistryError):
            pass
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        result = Net('74.125.225.229')
        self.assertRaises(ASNLookupError, result.get_asn_whois, 3, 'a')
Esempio n. 11
0
    def test_proxy_opener(self):
        try:
            from urllib.request import (OpenerDirector, ProxyHandler,
                                        build_opener)
        except ImportError:
            from urllib2 import (OpenerDirector, ProxyHandler, build_opener)

        result = Net('74.125.225.229')
        self.assertIsInstance(result.opener, OpenerDirector)

        handler = ProxyHandler()
        opener = build_opener(handler)
        result = Net(address='74.125.225.229', proxy_opener=opener)
        self.assertIsInstance(result.opener, OpenerDirector)
Esempio n. 12
0
    def test_get_asn_whois(self):
        data = ('15169   | 74.125.225.229   | 74.125.225.0/24     | US | arin'
                '     | 2007-03-13')
        result = Net('74.125.225.229')
        try:
            self.assertIsInstance(result.get_asn_whois(result=data), dict)
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        data = ('15169   | 74.125.225.229   | 74.125.225.0/24     | US | rdm'
                '     | 2007-03-13')
        result = Net('74.125.225.229')
        self.assertRaises(ASNRegistryError, result.get_asn_whois, 3, data)
Esempio n. 13
0
    def test_get_asn_whois(self):
        data = ('15169   | 74.125.225.229   | 74.125.225.0/24     | US | arin'
                '     | 2007-03-13')
        result = Net('74.125.225.229')
        try:
            self.assertIsInstance(result.get_asn_whois(result=data), dict)
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        data = ('15169   | 74.125.225.229   | 74.125.225.0/24     | US | rdm'
                '     | 2007-03-13')
        result = Net('74.125.225.229')
        self.assertRaises(ASNRegistryError, result.get_asn_whois, 3, data)
Esempio n. 14
0
    def test_lookup_asn(self):
        result = Net('74.125.225.229')
        try:
            self.assertIsInstance(result.lookup_asn(), tuple)
        except (HTTPLookupError, ASNRegistryError):
            pass
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        result = Net('74.125.225.229', timeout=0, allow_permutations=False)
        self.assertRaises(ASNRegistryError, result.lookup_asn)

        result = Net('74.125.225.229', timeout=0, allow_permutations=True)
        self.assertRaises(HTTPLookupError, result.lookup_asn, **dict(
            asn_alts=['http']
        ))
Esempio n. 15
0
    def test_get_asn_dns(self):
        data = ['"15169 ', ' 74.125.225.0/24 ', ' US ', ' arin ',
                ' 2007-03-13"']
        result = Net('74.125.225.229')
        try:
            self.assertIsInstance(result.get_asn_dns(result=data), dict)
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        data = ['"15169 ', ' 74.125.225.0/24 ', ' US ', ' random ',
                ' 2007-03-13"']
        result = Net('74.125.225.229')
        self.assertRaises(ASNRegistryError, result.get_asn_dns, data)

        data = []
        result = Net('74.125.225.229')
        self.assertRaises(ASNLookupError, result.get_asn_dns, data)
Esempio n. 16
0
    def test_get_host(self):
        ips = [
            '74.125.225.229',  # ARIN
            '2001:4860:4860::8888'
        ]

        for ip in ips:
            result = Net(ip)
            try:
                self.assertIsInstance(result.get_host(0), tuple)
            except HostLookupError:
                pass
            except AssertionError as e:
                raise e
            except Exception as e:
                self.fail('Unexpected exception raised: {0}'.format(e))

        result = Net('74.125.225.229', 0)
        self.assertRaises(HostLookupError, result.get_host,
                          **dict(retry_count=1))
Esempio n. 17
0
    def test_get_host(self):
        ips = [
            '74.125.225.229',  # ARIN
            '2001:4860:4860::8888'
        ]

        for ip in ips:
            result = Net(ip)
            try:
                self.assertIsInstance(result.get_host(0), tuple)
            except HostLookupError:
                pass
            except AssertionError as e:
                raise e
            except Exception as e:
                self.fail('Unexpected exception raised: %r' % e)

        result = Net('74.125.225.229', 0)
        self.assertRaises(HostLookupError, result.get_host, **dict(
            retry_count=1))
Esempio n. 18
0
    def test_get_whois(self):
        result = Net('74.125.225.229')
        try:
            self.assertIsInstance(result.get_whois(), str)
        except WhoisLookupError:
            pass
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: %r' % e)

        self.assertRaises(WhoisLookupError, result.get_whois, **dict(
            retry_count=0, server='arin.net'))

        self.assertRaises(BlacklistError, result.get_whois, **dict(
            server='whois.arin.net', extra_blacklist=['whois.arin.net']))

        result = Net('74.125.225.229', 0)
        self.assertRaises(WhoisLookupError, result.get_whois, **dict(
            retry_count=1))
Esempio n. 19
0
    def test_get_whois(self):
        result = Net('74.125.225.229')
        try:
            self.assertIsInstance(result.get_whois(), str)
        except WhoisLookupError:
            pass
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        self.assertRaises(WhoisLookupError, result.get_whois,
                          **dict(retry_count=0, server='arin.net'))

        self.assertRaises(
            BlacklistError, result.get_whois,
            **dict(server='whois.arin.net',
                   extra_blacklist=['whois.arin.net']))

        result = Net('74.125.225.229', 0)
        self.assertRaises(WhoisLookupError, result.get_whois,
                          **dict(retry_count=1))
Esempio n. 20
0
    def test_get_http_raw(self):
        from ipwhois.net import NIR

        # GET
        result = Net('133.1.2.5')
        try:
            self.assertIsInstance(result.get_http_raw(
                NIR['jpnic']['url'].format('133.1.2.5')), str)
        except HTTPLookupError:
            pass
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        # POST
        result = Net('115.1.2.3')
        try:
            self.assertIsInstance(result.get_http_raw(
                url=NIR['krnic']['url'].format('115.1.2.3'),
                request_type=NIR['krnic']['request_type'],
                form_data={NIR['krnic']['form_data_ip_field']: '115.1.2.3'}
            ), str)
        except HTTPLookupError:
            pass
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        self.assertRaises(HTTPLookupError, result.get_http_raw, **dict(
            url='http://255.255.255.255', retry_count=1))

        result = Net(address='133.1.2.5', timeout=0)
        url = NIR['jpnic']['url'].format('133.1.2.5')
        self.assertRaises(HTTPLookupError, result.get_http_raw, **dict(
            url=url, retry_count=0))
Esempio n. 21
0
    def test_get_http_json(self):
        from ipwhois.rdap import RIR_RDAP
        result = Net('74.125.225.229')
        try:
            self.assertIsInstance(result.get_http_json(
                RIR_RDAP['arin']['ip_url'].format('74.125.225.229')), dict)
        except HTTPLookupError:
            pass
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        self.assertRaises(HTTPLookupError, result.get_http_json, **dict(
            url='http://255.255.255.255', retry_count=0))

        result = Net('74.125.225.229', 0)
        url = RIR_RDAP['arin']['ip_url'].format('74.125.225.229')
        self.assertRaises(HTTPLookupError, result.get_http_json, **dict(
            url=url, retry_count=0))

        # Uncommenting below will result in a flood of up to 20 requests
        # to test rate limiting.
        '''
Esempio n. 22
0
    def test_lookup_asn(self):
        result = Net('74.125.225.229')
        try:
            self.assertIsInstance(result.lookup_asn(), tuple)
        except (HTTPLookupError, ASNRegistryError):
            pass
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        result = Net('74.125.225.229', timeout=0, allow_permutations=False)
        self.assertRaises(ASNRegistryError, result.lookup_asn)

        result = Net('74.125.225.229', timeout=0, allow_permutations=True)
        self.assertRaises(HTTPLookupError, result.lookup_asn,
                          **dict(asn_alts=['http']))
Esempio n. 23
0
    def test_get_asn_dns(self):
        data = [
            '"15169 ', ' 74.125.225.0/24 ', ' US ', ' arin ', ' 2007-03-13"'
        ]
        result = Net('74.125.225.229')
        try:
            self.assertIsInstance(result.get_asn_dns(result=data), dict)
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        data = [
            '"15169 ', ' 74.125.225.0/24 ', ' US ', ' random ', ' 2007-03-13"'
        ]
        result = Net('74.125.225.229')
        self.assertRaises(ASNRegistryError, result.get_asn_dns, data)

        data = []
        result = Net('74.125.225.229')
        self.assertRaises(ASNLookupError, result.get_asn_dns, data)
Esempio n. 24
0
    def test_get_asn_http(self):
        data = {"nets": {"net": {"orgRef": {"@handle": "APNIC"}}}}
        result = Net('1.2.3.4')
        try:
            self.assertIsInstance(result.get_asn_http(result=data), dict)
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        data['nets']['net']['orgRef']['@handle'] = 'RIPE'
        try:
            self.assertIsInstance(result.get_asn_http(result=data), dict)
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        data['nets']['net']['orgRef']['@handle'] = 'DNIC'
        try:
            self.assertIsInstance(result.get_asn_http(result=data), dict)
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        data['nets']['net']['orgRef']['@handle'] = 'INVALID'
        try:
            self.assertRaises(ASNRegistryError,
                              result.get_asn_http,
                              result=data)
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        data = ''
        try:
            self.assertIsInstance(result.get_asn_http(result=data), dict)
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))
Esempio n. 25
0
 def test_ip_version(self):
     result = Net('74.125.225.229')
     self.assertEqual(result.version, 4)
     result = Net('2001:4860:4860::8888')
     self.assertEqual(result.version, 6)
Esempio n. 26
0
 def test_timeout(self):
     result = Net('74.125.225.229')
     self.assertIsInstance(result.timeout, int)