Exemplo n.º 1
0
    def test_lookup(self):

        data_dir = path.abspath(path.join(path.dirname(__file__), '..'))

        with io.open(str(data_dir) + '/asn.json', 'r') as \
                data_file:
            data = json.load(data_file)

        # IP doesn't matter here
        net = Net('74.125.225.229')

        for key, val in data.items():

            log.debug('Testing: {0} - {1}'.format(key, val['asn']))

            obj = ASNOriginOld(net)
            try:

                self.assertIsInstance(obj.lookup(asn=val['asn']), dict)

            except ASNOriginLookupError:

                pass

            except AssertionError as e:

                raise e

            except Exception as e:

                self.fail('Unexpected exception raised: {0}'.format(e))

        net = Net(address='74.125.225.229', timeout=0, allow_permutations=True)
        asnorigin = ASNOriginOld(net)

        try:
            self.assertRaises(ASNOriginLookupError, asnorigin.lookup,
                              **dict(asn='15169', asn_alts=['http']))
        except AssertionError as e:
            raise self.failureException(
                '{}; This is supposed to fail after remove ASNOrigin class.'.
                format(e))

        try:

            self.assertRaises(ValueError, asnorigin.lookup,
                              **dict(asn='15169', asn_methods=['asd']))
        except AssertionError as e:
            raise self.failureException(
                '{}; This is supposed to fail after remove ASNOrigin class.'.
                format(e))

        net = Net(address='74.125.225.229')
        asnorigin = ASNOriginOld(net)
        asnorigin.lookup(asn='15169', asn_methods=['whois', 'http'])
Exemplo n.º 2
0
    def test__ASNOriginLookup(self):

        data_dir = path.dirname(__file__)

        with io.open(str(data_dir) + '/asn.json', 'r') as \
                data_file:
            data = json.load(data_file)

        for key, val in data.items():

            log.debug('Testing: {0}'.format(key))
            net = Net(key)
            obj = ASNOrigin(net)

            try:

                self.assertIsInstance(obj.lookup(asn=val['asn'],
                                                 inc_raw=True,
                                                 response=val['response']),
                                      dict)

            except AssertionError as e:

                raise e

            except Exception as e:

                self.fail('Unexpected exception raised: {0}'.format(e))
Exemplo n.º 3
0
def getAllroutesOld(asn):
    from ipwhois.net import Net
    from ipwhois.asn import ASNOrigin as ASNOriginCls
    net = Net('108.160.160.0')
    obj = ASNOriginCls(net)
    results = obj.lookup(asn)
    return [ipaddress.ip_network(_net['cidr']) for _net in results['nets']]
Exemplo n.º 4
0
    def test__ASNOriginLookup(self):

        data_dir = path.dirname(__file__)

        with io.open(str(data_dir) + '/asn.json', 'r') as \
                data_file:
            data = json.load(data_file)

        for key, val in data.items():

            log.debug('Testing: {0}'.format(key))
            net = Net(key)
            obj = ASNOrigin(net)

            try:

                self.assertIsInstance(obj.lookup(asn=val['asn'],
                                                 inc_raw=True,
                                                 response=val['response']),
                                      dict)

            except AssertionError as e:

                raise e

            except Exception as e:

                self.fail('Unexpected exception raised: {0}'.format(e))
Exemplo n.º 5
0
def get_networks_from_asn(asn_list):
    net = Net('2001:43f8:7b0::')
    asn_origin = ASNOrigin(net)
    networks = []
    for asn in ASN_LIST:
        nets = asn_origin.lookup(asn, field_list=['source'])['nets']
        networks.extend(ipaddress.ip_network(net['cidr']) for net in nets)

    return networks
 def __get_asn_nets(self, ip):
     asn_origin = self.__get_asn_origin(ip)
     origin = ASNOrigin(Net(ip))
     lookup = origin.lookup(asn='AS{}'.format(asn_origin),
                            asn_methods=['whois'])
     return lookup.get('nets')