-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdnsLookup.py
More file actions
45 lines (30 loc) · 863 Bytes
/
Copy pathdnsLookup.py
File metadata and controls
45 lines (30 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import requests
import json
import time
def lookup(target):
t0 = time.time()
end_point = 'https://rest.db.ripe.net/search.json'
params = { 'query-string' : target,
'flags' : 'no-filtering',
'source': 'RIPE'
}
response = requests.get(end_point, params=params)
data = json.loads(response.text)
return process(data)
def process(response):
attrs = [attrs['attributes']['attribute'] for attrs in response['objects']['object']]
output = {}
for attrz in attrs:
for attr in attrz:
output[attr['name']] = attr['value']
return output
if output.has_key('inetnum'): #ipv4
ip_range = output['inetnum']
low, high = ip_range.split(' - ')
output['ip_range'] = { 'low' : low,
'high' : high
}
return output
if __name__ == '__main__':
target = raw_input('Lookup what ip?\n> ')
dns_info = lookup(target)