-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
63 lines (50 loc) · 1.25 KB
/
tools.py
File metadata and controls
63 lines (50 loc) · 1.25 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# TODO recheck luminati resolvers
# TODO
import json
import pyasn
lum_resolvers_asn = [15169, 20473, 36692, 14061, 30607, 24940, 27725]
asndb = pyasn.pyasn('data/ipsan_db.dat')
lst = None
global_ip_to_asn = {}
lum_dict = {}
undecided_dict = {}
############################
f = open("data/all_ips.json")
d = json.load(f)
for ip in d:
global_ip_to_asn[ip] = 1
f = open("data/lum_ips.json")
d = json.load(f)
for ip in d:
lum_dict[ip] = 1
###########################
def get_asn(ip):
# TODO what returns for not present??
try:
asn = asndb.lookup(ip)[0]
if type(asn) != type(1):
return None
return asn
except:
return None
def look_up(resolver_ip):
asn = get_asn(resolver_ip)
if asn is None:
undecided_dict[resolver_ip] = 1
return True
else:
global_ip_to_asn[resolver_ip] = asn
if int(asn) in lum_resolvers_asn:
lum_dict[resolver_ip] = 1
return True
else:
return False
def is_lum_ip(resolver_ip):
if resolver_ip not in global_ip_to_asn:
if resolver_ip in undecided_dict:
return True
return look_up(resolver_ip)
if resolver_ip in lum_dict:
return True
return False
a = 1