From 2418d13d0718b8603af78cd05645b392c048601b Mon Sep 17 00:00:00 2001 From: Baptiste Jonglez Date: Mon, 27 Jan 2014 22:33:37 +0100 Subject: [PATCH] =?UTF-8?q?Add=20support=20for=20configuring=20the=20DNS-b?= =?UTF-8?q?ased=20ASN=20=E2=86=92=20name=20mapping=20service.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lg.cfg | 3 +++ lg.py | 8 +++++++- toolbox.py | 4 ---- 3 files changed, 10 insertions(+), 5 deletions(-) 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