Add support for configuring the DNS-based ASN → name mapping service.

This commit is contained in:
Baptiste Jonglez 2014-01-27 22:33:37 +01:00
parent ca7eb2b9ac
commit 2418d13d07
3 changed files with 10 additions and 5 deletions

3
lg.cfg
View File

@ -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'

8
lg.py
View File

@ -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 """

View File

@ -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