Cleaner solution for making the ASN service configurable
This commit is contained in:
parent
ada668055d
commit
fc6472071b
4 changed files with 10 additions and 7 deletions
3
lg.cfg
3
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'
|
||||
|
|
8
lg.py
8
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 """
|
||||
|
|
|
@ -29,10 +29,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.%s" % (n, ASN_ZONE) ,"TXT").replace("'","").replace('"','')
|
||||
return [ field.strip() for field in data.split("|") ]
|
||||
|
||||
def mask_is_valid(n):
|
||||
if not n:
|
||||
return True
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
# DNS zone to query for ASN -> name mapping
|
||||
ASN_ZONE = "asn.cymru.com"
|
Loading…
Add table
Reference in a new issue