Handle root permission requirement on certain platforms
also few a handful of nasty bugs
This commit is contained in:
parent
8892984c2d
commit
77df91f18f
@ -171,7 +171,17 @@ def main():
|
|||||||
if should_stop:
|
if should_stop:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# some platforms permit opening a DGRAM socket for ICMP without root permission
|
||||||
|
# if not availble, we will fall back to RAW which explicitly requires root permission
|
||||||
|
try:
|
||||||
|
icmp_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, icmp)
|
||||||
|
except OSError:
|
||||||
|
try:
|
||||||
icmp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, icmp)
|
icmp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, icmp)
|
||||||
|
except OSError:
|
||||||
|
print("Error: Unable to create ICMP socket with unprivileged user. Please run as root.")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
icmp_socket.bind(("", dnsport))
|
icmp_socket.bind(("", dnsport))
|
||||||
icmp_socket.settimeout(timeout)
|
icmp_socket.settimeout(timeout)
|
||||||
|
|
||||||
@ -236,8 +246,13 @@ def main():
|
|||||||
if has_whois and as_lookup:
|
if has_whois and as_lookup:
|
||||||
ASN = whoisrecord(curr_addr)
|
ASN = whoisrecord(curr_addr)
|
||||||
as_name = ''
|
as_name = ''
|
||||||
|
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:
|
||||||
|
if should_stop:
|
||||||
|
exit(0)
|
||||||
|
pass
|
||||||
|
|
||||||
print("%d\t%s (%s) %s%d ms" % (ttl, curr_name, curr_addr, as_name, elapsed))
|
print("%d\t%s (%s) %s%d ms" % (ttl, curr_name, curr_addr, as_name, elapsed))
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user