mirror of
https://github.com/adulau/DomainClassifier.git
synced 2024-11-22 18:07:07 +00:00
Better error catching
- Timeout of DNS reduce to 1 sec - Socket exception catched - Ranking default value is now 1.0
This commit is contained in:
parent
738060ab57
commit
0be08a31c6
1 changed files with 26 additions and 13 deletions
|
@ -27,6 +27,7 @@ class Extract:
|
|||
self.rawtext = rawtext
|
||||
self.presolver = dns.resolver.Resolver()
|
||||
self.presolver.nameservers = ['149.13.33.69']
|
||||
self.presolver.lifetime = 1.0
|
||||
self.bgprankingserver = 'pdns.circl.lu'
|
||||
self.vdomain = []
|
||||
|
||||
|
@ -38,7 +39,9 @@ class Extract:
|
|||
|
||||
if ipaddr:
|
||||
clook = IPy.IP(str(ipaddr)).reverseName().replace('.in-addr.arpa.','.origin.asn.cymru.com')
|
||||
a = self.presolver.query(clook, 'TXT')
|
||||
try: a = self.presolver.query(clook, 'TXT')
|
||||
except dns.resolver.NXDOMAIN: return None
|
||||
except dns.exception.Timeout: return None
|
||||
if a:
|
||||
x = str(a[0]).split("|")
|
||||
# why so many spaces?
|
||||
|
@ -61,10 +64,15 @@ class Extract:
|
|||
break
|
||||
s.close()
|
||||
if len(r) > 0:
|
||||
rank = r.split("\n")[1].split(",")[1]
|
||||
try: rr = r.split("\n")[1].split(",")
|
||||
except IndexError: return None
|
||||
if len(rr) > 1:
|
||||
rank = rr[1]
|
||||
return float(rank)
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
return None
|
||||
|
||||
"""domain method extracts potential domains matching any
|
||||
string that is a serie of string with maximun 63 character separated by a
|
||||
|
@ -136,16 +144,21 @@ class Extract:
|
|||
if self.validdomain:
|
||||
for dom in self.validdomain:
|
||||
rank = None
|
||||
asn = None
|
||||
if dom[1] == 'A':
|
||||
ip = dom[2]
|
||||
asn = self.__origin(ipaddr=dom[2])[0]
|
||||
o = self.__origin(ipaddr=dom[2])
|
||||
if o:
|
||||
asn = o[0]
|
||||
rank = self.__bgpranking(asn)
|
||||
t = (rank, dom[0])
|
||||
self.rankdom.append(t)
|
||||
elif dom[1] == 'CNAME':
|
||||
cname = str(dom[2])
|
||||
ip = socket.gethostbyname(cname)
|
||||
asn = self.__origin(ipaddr=ip)[0]
|
||||
try: ip = socket.gethostbyname(cname)
|
||||
except: continue
|
||||
try: asn = self.__origin(ipaddr=ip)[0]
|
||||
except TypeError: continue
|
||||
rank = self.__bgpranking(asn)
|
||||
t = (rank, dom[0])
|
||||
self.rankdom.append(t)
|
||||
|
|
Loading…
Reference in a new issue