use whois instead cymru.com
(missing support for 4byte ASN, etc.) Conflicts: lg.py toolbox.py
This commit is contained in:
parent
1b04941e9b
commit
9bea48e0e8
3 changed files with 12 additions and 15 deletions
|
@ -26,7 +26,4 @@ AS_NUMBER = {
|
|||
|
||||
#WHOIS_SERVER = "whois.foo.bar"
|
||||
|
||||
# DNS zone to query for ASN -> name mapping
|
||||
ASN_ZONE = "asn.cymru.com"
|
||||
|
||||
SESSION_KEY = '\xd77\xf9\xfa\xc2\xb5\xcd\x85)`+H\x9d\xeeW\\%\xbe/\xbaT\x89\xe8\xa7'
|
||||
|
|
13
lg.py
13
lg.py
|
@ -29,7 +29,7 @@ from urllib import quote, unquote
|
|||
import json
|
||||
import random
|
||||
|
||||
from toolbox import mask_is_valid, ipv6_is_valid, ipv4_is_valid, resolve, save_cache_pickle, load_cache_pickle, unescape
|
||||
from toolbox import mask_is_valid, ipv6_is_valid, ipv4_is_valid, resolve, save_cache_pickle, load_cache_pickle, get_asname_from_whois, unescape
|
||||
#from xml.sax.saxutils import escape
|
||||
|
||||
|
||||
|
@ -46,15 +46,6 @@ file_handler.setLevel(getattr(logging, app.config["LOG_LEVEL"].upper()))
|
|||
app.logger.addHandler(file_handler)
|
||||
|
||||
|
||||
def get_asn_from_as(n):
|
||||
asn_zone = app.config.get("ASN_ZONE", "asn.cymru.com")
|
||||
try:
|
||||
data = resolve("AS%s.%s" % (n, asn_zone) ,"TXT").replace("'","").replace('"','')
|
||||
except:
|
||||
return " "*5
|
||||
return [ field.strip() for field in data.split("|") ]
|
||||
|
||||
|
||||
def add_links(text):
|
||||
"""Browser a string and replace ipv4, ipv6, as number, with a
|
||||
whois link """
|
||||
|
@ -375,7 +366,7 @@ def get_as_name(_as):
|
|||
if not _as.isdigit():
|
||||
return _as.strip()
|
||||
|
||||
name = get_asn_from_as(_as)[-1].replace(" ","\r",1)
|
||||
name = get_asname_from_whois(whois_command('AS' + _as)).replace(" ","\r",1)
|
||||
return "AS%s | %s" % (_as, name)
|
||||
|
||||
|
||||
|
|
11
toolbox.py
11
toolbox.py
|
@ -23,12 +23,21 @@ from dns import resolver
|
|||
import socket
|
||||
import pickle
|
||||
import xml.parsers.expat
|
||||
import re
|
||||
|
||||
def resolve(n, q):
|
||||
return str(resolver.query(n,q)[0])
|
||||
|
||||
asname_regex = re.compile("as-name:\s+(?P<name>\S+)")
|
||||
|
||||
def get_asname_from_whois(data):
|
||||
r = asname_regex.search(data)
|
||||
if not r:
|
||||
return 'UNKNOWN-AS'
|
||||
return r.groupdict()['name']
|
||||
|
||||
def mask_is_valid(n):
|
||||
if not n:
|
||||
if not n:
|
||||
return True
|
||||
try:
|
||||
mask = int(n)
|
||||
|
|
Loading…
Add table
Reference in a new issue