Esempio n. 1
0
    def query(self, data):
        data_parsers = [
            x for x in self.parsers if x().matches_domain(self.domain)
        ]
        if len(data_parsers) > 1:
            raise WhoisError('BUG: more than one parser for domain %s: %s' %
                             (self.domain, [x.name for x in data_parsers]))

        if not data_parsers:
            raise WhoisError('No whois data parser found for domain %s' %
                             self.domain)

        formatter = data_parsers[0]()
        formatter.parse(self.domain, data)
        self.update(formatter.items())
Esempio n. 2
0
 def __parse_date_entry(self, data):
     if data is None:
         return None
     try:
         return dateparser(data['$'])
     except ValueError, KeyError:
         raise WhoisError('Error parsing date from %s' % data)
Esempio n. 3
0
 def __parse_number_entry(self, data):
     if data is None:
         return None
     try:
         return int(data['$'])
     except KeyError:
         raise WhoisError('Error parsing number field %s' % data)
Esempio n. 4
0
 def __parse_address_entry(self, data):
     if data is None:
         return None
     try:
         return self.address_format(data['$'])
     except ValueError, KeyError:
         raise WhoisError('Error parsing address from %s' % data)
Esempio n. 5
0
 def __init__(self, address):
     try:
         self.address = IPv4Address(address).ipaddress
         self.address_format = IPv4Address
     except ValueError:
         try:
             self.address = IPv6Address(address).address
             self.address_format = IPv6Address
         except ValueError:
             raise WhoisError('Unsupported address: %s' % address)
Esempio n. 6
0
def ARINReverseIPQuery(address, proxies={}):
    """ARIN IP Query

    Query ARIN REST API for IP allocation information details

    Returns ARINReverseIP object.

    """
    entry = ARINReverseIP(address)

    url = URL_TEMPLATE % {'address': entry.address}
    headers = {'Accept': 'application/arin.whoisrws-v1+json' }
    res = requests.get(url, headers=headers)
    if res.status_code != 200:
        raise WhoisError('Error fetching URL %s' % url)

    try:
        data = json.loads(res.content)
    except ValueError, emsg:
        raise WhoisError('Error parsing response: %s' % res.content)
Esempio n. 7
0
    def __parse_string_entry(self, data):
        if data is None:
            return None
        if 'line' in data:
            try:
                data = data['line']
                if isinstance(data, list):
                    data.sort(lambda a, b: cmp(int(a['@number']), int(b['@number'])))
                    return ' '.join([l['$'] for l in data])
                else:
                    return data['$']
            except AttributeError:
                raise WhoisError('Error parsing string field %s' % data)

        else:
            try:
                return data['$']
            except TypeError:
                raise WhoisError('Error parsing string field %s' % data)
            except KeyError:
                raise WhoisError('Error parsing string field %s' % data)
Esempio n. 8
0
    def match(self, address):
        try:
            if self.network.addressInNetwork(IPv4Address(address).address):
                return self
        except ValueError:
            try:
                if self.network.addressInNetwork(IPv6Address(address).address):
                    return self
            except ValueError:
                raise WhoisError('Error matching address %s to %s' % (address, self.network))

        return None
Esempio n. 9
0
    entry = ARINReverseIP(address)

    url = URL_TEMPLATE % {'address': entry.address}
    headers = {'Accept': 'application/arin.whoisrws-v1+json' }
    res = requests.get(url, headers=headers)
    if res.status_code != 200:
        raise WhoisError('Error fetching URL %s' % url)

    try:
        data = json.loads(res.content)
    except ValueError, emsg:
        raise WhoisError('Error parsing response: %s' % res.content)

    if 'net' not in data:
        logger.debug('DATA: %s' % res.content)
        raise WhoisError('Did not receive expected data: missing net section')
    net = data['net']
    assert isinstance(net, dict)

    for key in ( 'handle', 'name', 'comment', 'ref', 'version', ):
        if key in net:
            setattr(entry, key, net[key])

    for key, field in DATE_FIELD_MAP.items():
        try:
            setattr(entry, key, net[field])
        except KeyError:
            continue

    blocks = net['netBlocks']['netBlock']
    if isinstance(blocks, list):