support for arbitrary dns port for dnstraceroute
and some trivial cleanup and beatufications
This commit is contained in:
parent
d43b03909e
commit
d90cc4a8d5
@ -25,8 +25,6 @@
|
|||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
import dns.rdatatype
|
|
||||||
import dns.resolver
|
|
||||||
import getopt
|
import getopt
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
@ -34,6 +32,9 @@ import sys
|
|||||||
import time
|
import time
|
||||||
from statistics import stdev
|
from statistics import stdev
|
||||||
|
|
||||||
|
import dns.rdatatype
|
||||||
|
import dns.resolver
|
||||||
|
|
||||||
__VERSION__ = 1.0
|
__VERSION__ = 1.0
|
||||||
__PROGNAME__ = os.path.basename(sys.argv[0])
|
__PROGNAME__ = os.path.basename(sys.argv[0])
|
||||||
should_stop = False
|
should_stop = False
|
||||||
|
@ -37,14 +37,14 @@ from statistics import stdev
|
|||||||
import dns.rdatatype
|
import dns.rdatatype
|
||||||
import dns.resolver
|
import dns.resolver
|
||||||
|
|
||||||
__VERSION__ = 1.0
|
__VERSION__ = 1.1
|
||||||
__PROGNAME__ = os.path.basename(sys.argv[0])
|
__PROGNAME__ = os.path.basename(sys.argv[0])
|
||||||
should_stop = False
|
should_stop = False
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print('%s version %1.1f\n' % (__PROGNAME__, __VERSION__))
|
print('%s version %1.1f\n' % (__PROGNAME__, __VERSION__))
|
||||||
print('syntax: %s [-h] [-q] [-v] [-s server] [-c count] [-t type] [-w wait] hostname' % __PROGNAME__)
|
print('syntax: %s [-h] [-q] [-v] [-s server] [-p port] [-c count] [-t type] [-w wait] hostname' % __PROGNAME__)
|
||||||
print(' -h --help Show this help')
|
print(' -h --help Show this help')
|
||||||
print(' -q --quiet Quiet')
|
print(' -q --quiet Quiet')
|
||||||
print(' -v --verbose Print actual dns response')
|
print(' -v --verbose Print actual dns response')
|
||||||
@ -83,7 +83,8 @@ def main():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "qhc:s:t:w:vp:",
|
opts, args = getopt.getopt(sys.argv[1:], "qhc:s:t:w:vp:",
|
||||||
["help", "output=", "count=", "server=", "quiet", "type=", "wait=", "verbose", "port"])
|
["help", "output=", "count=", "server=", "quiet", "type=", "wait=", "verbose",
|
||||||
|
"port"])
|
||||||
except getopt.GetoptError as err:
|
except getopt.GetoptError as err:
|
||||||
# print help information and exit:
|
# print help information and exit:
|
||||||
print(err) # will print something like "option -a not recognized"
|
print(err) # will print something like "option -a not recognized"
|
||||||
@ -137,7 +138,6 @@ def main():
|
|||||||
|
|
||||||
print("%s DNS: %s:%d, hostname: %s, rdatatype: %s" % (__PROGNAME__, dnsserver, dest_port, hostname, dnsrecord))
|
print("%s DNS: %s:%d, hostname: %s, rdatatype: %s" % (__PROGNAME__, dnsserver, dest_port, hostname, dnsrecord))
|
||||||
|
|
||||||
|
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
if should_stop:
|
if should_stop:
|
||||||
break
|
break
|
||||||
|
@ -44,7 +44,7 @@ except ImportError:
|
|||||||
has_whois = False
|
has_whois = False
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
__VERSION__ = 1.0
|
__VERSION__ = 1.1
|
||||||
__PROGNAME__ = os.path.basename(sys.argv[0])
|
__PROGNAME__ = os.path.basename(sys.argv[0])
|
||||||
WHOIS_CACHE = 'whois.cache'
|
WHOIS_CACHE = 'whois.cache'
|
||||||
|
|
||||||
@ -85,11 +85,12 @@ if has_whois:
|
|||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print('%s version %1.1f\n' % (__PROGNAME__, __VERSION__))
|
print('%s version %1.1f\n' % (__PROGNAME__, __VERSION__))
|
||||||
print('syntax: %s [-h] [-q] [-s server] [-c count] [-t type] [-w wait] hostname' % __PROGNAME__)
|
print('syntax: %s [-h] [-q] [-a] [-s server] [-p port] [-c count] [-t type] [-w wait] hostname' % __PROGNAME__)
|
||||||
print(' -h --help Show this help')
|
print(' -h --help Show this help')
|
||||||
print(' -q --quiet Quiet')
|
print(' -q --quiet Quiet')
|
||||||
print(' -a --asn Turn on AS# lookups for each hop encountered')
|
print(' -a --asn Turn on AS# lookups for each hop encountered')
|
||||||
print(' -s --server DNS server to use (default: first system resolver)')
|
print(' -s --server DNS server to use (default: first system resolver)')
|
||||||
|
print(' -p --port DNS server port number (default: 53)')
|
||||||
print(' -c --count Maximum number of hops (default: 30)')
|
print(' -c --count Maximum number of hops (default: 30)')
|
||||||
print(' -w --wait Maximum wait time for a reply (default: 5)')
|
print(' -w --wait Maximum wait time for a reply (default: 5)')
|
||||||
print(' -t --type DNS request record type (default: A)')
|
print(' -t --type DNS request record type (default: A)')
|
||||||
@ -116,13 +117,13 @@ def main():
|
|||||||
timeout = 1
|
timeout = 1
|
||||||
quiet = False
|
quiet = False
|
||||||
dnsserver = dns.resolver.get_default_resolver().nameservers[0]
|
dnsserver = dns.resolver.get_default_resolver().nameservers[0]
|
||||||
dnsport = 53
|
dest_port = 53
|
||||||
hops = 0
|
hops = 0
|
||||||
as_lookup = False
|
as_lookup = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "aqhc:s:t:w:",
|
opts, args = getopt.getopt(sys.argv[1:], "aqhc:s:t:w:p:",
|
||||||
["help", "output=", "count=", "server=", "quiet", "type=", "wait=", "asn"])
|
["help", "output=", "count=", "server=", "quiet", "type=", "wait=", "asn", "port"])
|
||||||
except getopt.GetoptError as err:
|
except getopt.GetoptError as err:
|
||||||
# print help information and exit:
|
# print help information and exit:
|
||||||
print(err) # will print something like "option -a not recognized"
|
print(err) # will print something like "option -a not recognized"
|
||||||
@ -146,6 +147,8 @@ def main():
|
|||||||
timeout = int(a)
|
timeout = int(a)
|
||||||
elif o in ("-t", "--type"):
|
elif o in ("-t", "--type"):
|
||||||
dnsrecord = a
|
dnsrecord = a
|
||||||
|
elif o in ("-p", "--port"):
|
||||||
|
dest_port = int(a)
|
||||||
elif o in ("-a", "--asn"):
|
elif o in ("-a", "--asn"):
|
||||||
if has_whois:
|
if has_whois:
|
||||||
as_lookup = True
|
as_lookup = True
|
||||||
@ -165,7 +168,7 @@ def main():
|
|||||||
ttl = 1
|
ttl = 1
|
||||||
reached = False
|
reached = False
|
||||||
|
|
||||||
print("%s %s: hostname=%s rdatatype=%s" % (__PROGNAME__, dnsserver, hostname, dnsrecord))
|
print("%s DNS: %s:%d, hostname: %s, rdatatype: %s" % (__PROGNAME__, dnsserver, dest_port, hostname, dnsrecord))
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if should_stop:
|
if should_stop:
|
||||||
@ -182,7 +185,7 @@ def main():
|
|||||||
print("Error: Unable to create ICMP socket with unprivileged user. Please run as root.")
|
print("Error: Unable to create ICMP socket with unprivileged user. Please run as root.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
icmp_socket.bind(("", dnsport))
|
icmp_socket.bind(("", dest_port))
|
||||||
icmp_socket.settimeout(timeout)
|
icmp_socket.settimeout(timeout)
|
||||||
|
|
||||||
try: # send DNS request
|
try: # send DNS request
|
||||||
|
Loading…
x
Reference in New Issue
Block a user