Skip to content

Commit

Permalink
Updated whois script to fallback to cymru DNS. Improves AS-Name detec…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
TimEvens committed Sep 17, 2018
1 parent ef549b9 commit 37e9240
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cron_scripts/gen-whois/gen_whois_asn.py
Expand Up @@ -17,6 +17,7 @@
from time import sleep
import subprocess
import traceback
import dns.resolver

TBL_GEN_WHOIS_ASN_NAME = "info_asn"

Expand Down Expand Up @@ -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):

Expand Down
2 changes: 2 additions & 0 deletions docs/BUILD.md
Expand Up @@ -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
Expand Down

0 comments on commit 37e9240

Please sign in to comment.