From 37e92408e93e8000b18ba25f51d32be213d9cd4e Mon Sep 17 00:00:00 2001 From: Tim Evens Date: Mon, 17 Sep 2018 08:53:25 -0700 Subject: [PATCH] Updated whois script to fallback to cymru DNS. Improves AS-Name detection --- cron_scripts/gen-whois/gen_whois_asn.py | 20 ++++++++++++++++++++ docs/BUILD.md | 2 ++ 2 files changed, 22 insertions(+) diff --git a/cron_scripts/gen-whois/gen_whois_asn.py b/cron_scripts/gen-whois/gen_whois_asn.py index 7daf45c..f791bac 100755 --- a/cron_scripts/gen-whois/gen_whois_asn.py +++ b/cron_scripts/gen-whois/gen_whois_asn.py @@ -17,6 +17,7 @@ from time import sleep import subprocess import traceback +import dns.resolver TBL_GEN_WHOIS_ASN_NAME = "info_asn" @@ -252,6 +253,25 @@ def walkWhois(db, asnList): record['source'] = source break + # If not found via whois, try DNS + if 'as_name' not in record: + try: + answers = dns.resolver.query("AS%d.asn.cymru.com" % asn, 'TXT') + if len(answers) >= 1: + txt = str(answers[0]).split("|") + if len(txt) >= 5: + a_name = txt[4].split(' - ', 2) + as_name = a_name[0].replace('"', '').strip() + org_name = a_name[1].replace('"', '').strip() if len(a_name) > 1 else as_name + + record['source'] = "cymru-" + txt[2].strip() + record['as_number'] = txt[0].strip() + record['as_name'] = as_name + record['country'] = txt[1].strip() + record['org_name'] = org_name + except: + pass + # Only process the record if whois responded if ('as_name' in record): diff --git a/docs/BUILD.md b/docs/BUILD.md index c5eede3..745e864 100644 --- a/docs/BUILD.md +++ b/docs/BUILD.md @@ -5,10 +5,12 @@ Dependencies - Java 1.8 or greater - Maven 3.x or greater - Python psycopg2-binary +- DNS Python #### Example: Install depends on Ubuntu 16.04: sudo apt-get install git openjdk-9-jdk git openjdk-9-jre-headless maven sudo pip install psycopg2-binary + sudo pip install dnspython Build