check: be more verbose
This commit is contained in:
parent
7e72c4403f
commit
6fe2c14976
|
@ -7,9 +7,28 @@ import subprocess
|
||||||
import nmap
|
import nmap
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
ip4, ip6 = 0, 0
|
||||||
|
|
||||||
|
|
||||||
|
ANSI_COLOR_ERR = "\x1b[31m"
|
||||||
|
ANSI_COLOR_WARN = "\x1b[33m"
|
||||||
|
ANSI_COLOR_OK = "\x1b[32m"
|
||||||
|
ANSI_COLOR_RESET = "\x1b[0m"
|
||||||
|
|
||||||
|
|
||||||
def error(*arg):
|
def error(*arg):
|
||||||
print(*arg, file=sys.stderr)
|
print(ANSI_COLOR_ERR, *arg, file=sys.stderr,
|
||||||
|
end='%s\n' % ANSI_COLOR_RESET)
|
||||||
|
|
||||||
|
|
||||||
|
def warn(*arg):
|
||||||
|
print(ANSI_COLOR_WARN, *arg, file=sys.stderr,
|
||||||
|
end='%s\n' % ANSI_COLOR_RESET)
|
||||||
|
|
||||||
|
|
||||||
|
def ok(*arg):
|
||||||
|
print(ANSI_COLOR_OK, *arg, file=sys.stderr,
|
||||||
|
end='%s\n' % ANSI_COLOR_RESET)
|
||||||
|
|
||||||
|
|
||||||
def check_host_lookup(hostname, port):
|
def check_host_lookup(hostname, port):
|
||||||
|
@ -32,11 +51,13 @@ def check_icmp_reachability(gai_record):
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
child.communicate()
|
child.communicate()
|
||||||
if child.returncode:
|
if child.returncode:
|
||||||
error(" - {host} is icmp unreachable".format(host=host))
|
error("{host} is icmp unreachable".format(host=host))
|
||||||
return True if child.returncode == 0 else False
|
return True if child.returncode == 0 else False
|
||||||
|
|
||||||
|
|
||||||
def check_udp_reachability(gai_record):
|
def check_udp_reachability(gai_record):
|
||||||
|
global ip4, ip6
|
||||||
|
|
||||||
host, port = gai_record[4][:2]
|
host, port = gai_record[4][:2]
|
||||||
family = gai_record[0]
|
family = gai_record[0]
|
||||||
|
|
||||||
|
@ -50,8 +71,17 @@ def check_udp_reachability(gai_record):
|
||||||
state = result['scan'][host]['udp'][port]['state']
|
state = result['scan'][host]['udp'][port]['state']
|
||||||
|
|
||||||
if state == 'closed':
|
if state == 'closed':
|
||||||
print(" - {host} port {port}/udp is {state}"
|
error("{host} port {port}/udp is {state}"
|
||||||
.format(host=host, port=port, state=state))
|
.format(host=host, port=port, state=state))
|
||||||
|
else:
|
||||||
|
ok("{host} port {port}/udp is {state}"
|
||||||
|
.format(host=host, port=port, state=state))
|
||||||
|
|
||||||
|
if family is socket.AddressFamily.AF_INET:
|
||||||
|
ip4 += 1
|
||||||
|
else:
|
||||||
|
ip6 += 1
|
||||||
|
|
||||||
return False if state == 'closed' else True
|
return False if state == 'closed' else True
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,9 +144,16 @@ def get_hosts_data(srcdir):
|
||||||
|
|
||||||
|
|
||||||
def do_checks(srcdir):
|
def do_checks(srcdir):
|
||||||
|
global ip4, ip6
|
||||||
|
|
||||||
errcnt = 0
|
errcnt = 0
|
||||||
|
warncnt = 0
|
||||||
|
|
||||||
for host in get_hosts_data(srcdir):
|
for host in get_hosts_data(srcdir):
|
||||||
print("Checking {community}".format(community=host['community']))
|
print("Checking {community}".format(community=host['community']))
|
||||||
|
if not host['addresses']:
|
||||||
|
warn("no addresses specified")
|
||||||
|
warncnt += 1
|
||||||
for address in host['addresses']:
|
for address in host['addresses']:
|
||||||
host, port = address
|
host, port = address
|
||||||
|
|
||||||
|
@ -126,7 +163,7 @@ def do_checks(srcdir):
|
||||||
errcnt += 1
|
errcnt += 1
|
||||||
else:
|
else:
|
||||||
for record in records:
|
for record in records:
|
||||||
if record[1] is not socket.SocketType.SOCK_DGRAM:
|
if record[1] is not socket.SOCK_DGRAM:
|
||||||
# vpn connections are udp based, so skip
|
# vpn connections are udp based, so skip
|
||||||
# everything else
|
# everything else
|
||||||
continue
|
continue
|
||||||
|
@ -138,7 +175,10 @@ def do_checks(srcdir):
|
||||||
if not port_state:
|
if not port_state:
|
||||||
errcnt += 1
|
errcnt += 1
|
||||||
|
|
||||||
print("{errcnt} errors".format(errcnt=errcnt))
|
print("\nfound {}/{} working ipv4/ipv6 peers".format(ip4, ip6))
|
||||||
|
|
||||||
|
error("{} errors".format(errcnt))
|
||||||
|
warn("{} warnings".format(warncnt))
|
||||||
|
|
||||||
return 0 if errcnt == 0 else 1
|
return 0 if errcnt == 0 else 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue