Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F31616543
raw.txt
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
ayounsi
Feb 14 2020, 6:18 PM
2020-02-14 18:18:42 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
raw.txt
View Options
import json
import time
import urllib.request
response = urllib.request.urlopen('https://as286.net/data/ana-invalids.txt')
raw_invalids_list = response.read().decode("utf-8")
problematic_asns = {}
for line in raw_invalids_list.splitlines():
if 'altpfx=NONE' in line or 'altpfx=PARTIAL' in line:
prefix, asn_raw, everything_else = line.split(';', 2)
# TODO tackle case where a prefix is coming from several AS#
if 'srcASes' in asn_raw:
continue
asn = int(asn_raw.replace('srcAS=', ''))
if asn in problematic_asns:
if prefix not in problematic_asns[asn]['prefixes']:
problematic_asns[asn]['prefixes'].append(prefix)
else:
problematic_asns[asn] = {}
problematic_asns[asn]['prefixes'] = [prefix]
print(len(problematic_asns))
no_noc_or_abuse = 0
no_noc = 0
http_error = 0
for asn, data in problematic_asns.items():
# To not hammer the API
time.sleep(1)
email = ''
try:
with urllib.request.urlopen("https://stat.ripe.net/data/whois/data.json?resource=" + str(asn)) as url:
raw_whois = json.loads(url.read().decode())
for records in raw_whois['data']['records']:
for contacts in records:
if contacts['key'] == 'OrgNOCEmail':
email = contacts['value']
break
if email:
break
if not email:
no_noc += 1
with urllib.request.urlopen("https://stat.ripe.net/data/abuse-contact-finder/data.json?resource=" + str(asn)) as url:
raw_abuse = json.loads(url.read().decode())
try:
email = raw_abuse['data']['anti_abuse_contacts']['abuse_c'][0]['email']
except (IndexError, KeyError):
print("Can't find NOC or Abuse contact for AS" + str(asn))
no_noc_or_abuse += 1
problematic_asns[asn]['email'] = email
except urllib.error.HTTPError as e:
print('Error while fetching AS' + str(asn) + ' ' + str(e))
http_error += 1
print(no_noc_or_abuse)
print(no_noc)
print(http_error)
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
8320552
Default Alt Text
raw.txt (2 KB)
Attached To
Mode
P10416 email-rpki-unreach.py
Attached
Detach File
Event Timeline
Log In to Comment