Skip to content

Commit 91f43d2

Browse files
committed
fix edge-cases
1 parent b41bb86 commit 91f43d2

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/builder/build.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,23 @@ def build_dbs_ip_asn(reports: dict, ptrs: dict, lookup_lists: dict, networks: di
5050
IPv4Address(ip)
5151
mmdb4.insert_network(ipset, {**asn_info['full'], **net})
5252

53-
if asn not in json4:
54-
json4[asn] = {}
53+
if asn != 0:
54+
if asn not in json4:
55+
json4[asn] = {}
5556

56-
json4[asn][ip] = {**asn_info['small'], **net_sm}
57+
json4[asn][ip] = {**asn_info['small'], **net_sm}
5758

5859
except AddressValueError:
5960
mmdb6.insert_network(ipset, {**asn_info['full'], **net})
6061

61-
if asn not in json6:
62-
json6[asn] = {}
62+
if asn != 0:
63+
if asn not in json6:
64+
json6[asn] = {}
6365

64-
json6[asn][ip] = {**asn_info['small'], **net_sm}
66+
json6[asn][ip] = {**asn_info['small'], **net_sm}
67+
68+
if asn == 0:
69+
continue
6570

6671
if asn not in asn_reports:
6772
try:
@@ -94,13 +99,13 @@ def build_dbs_ip_asn(reports: dict, ptrs: dict, lookup_lists: dict, networks: di
9499
}
95100

96101
if not asn_reports[asn]['kind']['hosting']:
97-
asn_info = str(asn_reports[asn]['info']['org']).lower()
98-
if asn_info.find('cloud') != -1 or asn_info.find('hosting') != -1:
102+
asn_org = str(asn_reports[asn]['info']['org']).lower()
103+
if asn_org.find('cloud') != -1 or asn_org.find('host') != -1:
99104
asn_reports[asn]['kind']['hosting'] = True
100105

101106
except KeyError as e:
102-
print(f'ERROR: Failed to lookup metadata of ASN {asn} ({e})')
103-
asn_reports[asn] = {'reports': ip_reports}
107+
print(f'ERROR: Failed to lookup metadata of ASN {asn} (KeyError: {e})')
108+
continue
104109

105110
else:
106111
for report_type, report_count in ip_reports.items():

src/builder/enrich_data.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,15 @@ def ip_asn_info(ip: str, reports: dict, lookup_lists: dict, ptrs: dict) -> dict:
6262
ip_md = m.get(ip)
6363

6464
try:
65-
asn = int(ip_md['asn'][2:])
65+
asn = int(ip_md['asn'])
66+
# asn = int(ip_md['asn'][2:]) # ipinfo DB
6667

6768
except ValueError:
68-
return {}
69+
return {
70+
'nr': 0,
71+
'full': {},
72+
'small': {},
73+
}
6974

7075
d = {
7176
'asn': asn,
@@ -110,7 +115,8 @@ def net_asn_info(ip: str) -> dict:
110115
ip_md = m.get(ip)
111116

112117
try:
113-
asn = int(ip_md['asn'][2:])
118+
asn = int(ip_md['asn'])
119+
# asn = int(ip_md['asn'][2:]) # ipinfo DB
114120

115121
except ValueError:
116122
return {}

0 commit comments

Comments
 (0)