Browse Source

ris.py: switch to dns query to have builtin cache

master
Alarig Le Lay 3 months ago
parent
commit
46a90db4f9
No known key found for this signature in database
GPG Key ID: C865491BF197B54F
  1. 14
      ris.py

14
ris.py

@ -1,13 +1,13 @@
#!/usr/bin/env python
import argparse
import cymruwhois
import itertools
import json
import pydot
import random
import time
import urllib.request
from dns import resolver
parser = argparse.ArgumentParser(description='''
Draw a graph from RIS BGP data. A PNG file will be generated with name
@ -46,18 +46,24 @@ edges = {}
dot_graph = pydot.Dot('BGPMAP', graph_type='digraph')
cymruwhois_client = cymruwhois.Client()
resolv = resolver.Resolver()
resolv.timeout = 0.5
for peer in paths:
print(peer, paths[peer])
string_prepended_path = ['AS'+v for v in paths[peer][:-1]]
print(string_prepended_path)
cymruwhois_query = cymruwhois_client.lookupmany_dict(string_prepended_path)
for previous_asn, asn in pairwise(paths[peer]):
as_name = cymruwhois_query['AS'+previous_asn].owner
try:
as_name = resolv.query(f"AS{previous_asn}.asn.cymru.com", "TXT")
as_name = as_name.response.answer[0].to_text().split('|')[4]
as_name = as_name.strip().replace("'","").replace('"','')
except Exception as e:
print(e, previous_asn)
as_name = ''
print(as_name)
edge_tuple = (previous_asn, asn)

Loading…
Cancel
Save