Refactor and comments
This commit is contained in:
parent
f74b311170
commit
d79f5821c5
@ -38,23 +38,25 @@ import time
|
|||||||
import dns.query
|
import dns.query
|
||||||
import dns.rdatatype
|
import dns.rdatatype
|
||||||
import dns.resolver
|
import dns.resolver
|
||||||
|
|
||||||
from cymruwhois import cymruwhois
|
from cymruwhois import cymruwhois
|
||||||
|
|
||||||
__author__ = 'Babak Farrokhi (babak@farrokhi.net)'
|
__author__ = 'Babak Farrokhi (babak@farrokhi.net)'
|
||||||
__license__ = 'BSD'
|
__license__ = 'BSD'
|
||||||
__version__ = 1.4
|
__version__ = 1.4
|
||||||
_ttl = None
|
_ttl = None
|
||||||
|
quiet = False
|
||||||
|
|
||||||
|
|
||||||
class custom_socket(socket.socket):
|
class CustomSocket(socket.socket):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(custom_socket, self).__init__(*args, **kwargs)
|
super(CustomSocket, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def sendto(self, *args, **kwargs):
|
def sendto(self, *args, **kwargs):
|
||||||
global _ttl
|
global _ttl
|
||||||
if _ttl:
|
if _ttl:
|
||||||
self.setsockopt(socket.SOL_IP, socket.IP_TTL, _ttl)
|
self.setsockopt(socket.SOL_IP, socket.IP_TTL, _ttl)
|
||||||
super(custom_socket, self).sendto(*args, **kwargs)
|
super(CustomSocket, self).sendto(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def test_import():
|
def test_import():
|
||||||
@ -92,14 +94,14 @@ def whoisrecord(ip):
|
|||||||
currenttime = time.time()
|
currenttime = time.time()
|
||||||
ts = currenttime
|
ts = currenttime
|
||||||
if ip in whois:
|
if ip in whois:
|
||||||
ASN, ts = whois[ip]
|
asn, ts = whois[ip]
|
||||||
else:
|
else:
|
||||||
ts = 0
|
ts = 0
|
||||||
if ((currenttime - ts) > 36000):
|
if (currenttime - ts) > 36000:
|
||||||
c = cymruwhois.Client()
|
c = cymruwhois.Client()
|
||||||
ASN = c.lookup(ip)
|
asn = c.lookup(ip)
|
||||||
whois[ip] = (ASN, currenttime)
|
whois[ip] = (asn, currenttime)
|
||||||
return ASN
|
return asn
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return e
|
return e
|
||||||
|
|
||||||
@ -166,7 +168,7 @@ def expert_report(trace_path, color_mode):
|
|||||||
print(" %s[*]%s public DNS server is next to a reserved IP address (possible hijacking)" % (color.R, color.N))
|
print(" %s[*]%s public DNS server is next to a reserved IP address (possible hijacking)" % (color.R, color.N))
|
||||||
return
|
return
|
||||||
|
|
||||||
## no expert info available
|
# no expert info available
|
||||||
print(" %s[*]%s No expert hint available for this trace" % (color.G, color.N))
|
print(" %s[*]%s No expert hint available for this trace" % (color.G, color.N))
|
||||||
|
|
||||||
|
|
||||||
@ -175,7 +177,7 @@ def ping(resolver, hostname, dnsrecord, ttl):
|
|||||||
|
|
||||||
reached = False
|
reached = False
|
||||||
|
|
||||||
dns.query.socket_factory = custom_socket
|
dns.query.socket_factory = CustomSocket
|
||||||
_ttl = ttl
|
_ttl = ttl
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -221,7 +223,6 @@ def main():
|
|||||||
dnsrecord = 'A'
|
dnsrecord = 'A'
|
||||||
count = 30
|
count = 30
|
||||||
timeout = 1
|
timeout = 1
|
||||||
quiet = False
|
|
||||||
dnsserver = dns.resolver.get_default_resolver().nameservers[0]
|
dnsserver = dns.resolver.get_default_resolver().nameservers[0]
|
||||||
dest_port = 53
|
dest_port = 53
|
||||||
hops = 0
|
hops = 0
|
||||||
@ -348,11 +349,11 @@ def main():
|
|||||||
if curr_addr:
|
if curr_addr:
|
||||||
as_name = ""
|
as_name = ""
|
||||||
if as_lookup:
|
if as_lookup:
|
||||||
ASN = whoisrecord(curr_addr)
|
asn = whoisrecord(curr_addr)
|
||||||
as_name = ''
|
as_name = ''
|
||||||
try:
|
try:
|
||||||
if ASN and ASN.asn != "NA":
|
if asn and asn.asn != "NA":
|
||||||
as_name = "[%s %s] " % (ASN.asn, ASN.owner)
|
as_name = "[%s %s] " % (asn.asn, asn.owner)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
if shutdown:
|
if shutdown:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user