ris.py: switch to dns query to have builtin cache
This commit is contained in:
parent
7bbdcb2204
commit
46a90db4f9
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…
Reference in a new issue