diff --git a/lg.cfg b/lg.cfg index 9211d03..55db922 100644 --- a/lg.cfg +++ b/lg.cfg @@ -23,4 +23,7 @@ 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' diff --git a/lg.py b/lg.py index 7d409d7..c39aa22 100644 --- a/lg.py +++ b/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, get_asn_from_as, unescape +from toolbox import mask_is_valid, ipv6_is_valid, ipv4_is_valid, resolve, save_cache_pickle, load_cache_pickle, unescape #from xml.sax.saxutils import escape @@ -46,6 +46,12 @@ 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") + data = resolve("AS%s.%s" % (n, asn_zone) ,"TXT").replace("'","").replace('"','') + 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 """ diff --git a/toolbox.py b/toolbox.py index 1543b85..534ddc9 100644 --- a/toolbox.py +++ b/toolbox.py @@ -27,10 +27,6 @@ import xml.parsers.expat def resolve(n, q): return str(resolver.query(n,q)[0]) -def get_asn_from_as(n): - data = resolve("AS%s.asn.cymru.com" % n ,"TXT").replace("'","").replace('"','') - return [ field.strip() for field in data.split("|") ] - def mask_is_valid(n): if not n: return True