18 parser = argparse.ArgumentParser(prog='Scanner.')
19 parser.add_argument('-s', action="store", help='subnet')
20 parser.add_argument('-host', action="store", help='host')
21 parser.add_argument('-p', action="store", help='ports')
23 args = parser.parse_args()
24 if len(sys.argv[1:])==0:
25 print "Choose a -s or -host"
27 print "-host for single host"
33 ports=args.p.split(",")
42 def scanner(host,port):
47 cert = ssl.get_server_certificate((str(host), int(port)))
48 x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
49 writer.writerow({'HOST': str(host), 'PORT': str(port), 'EXPIRED': format(x509.has_expired()), 'VALID FROM': format(x509.get_notBefore()), 'VALID UNTIL': format(x509.get_notAfter())})
50 except (error, timeout) as err:
54 with open('hosts.csv', 'w') as hostfile:
55 fieldnames = ['HOST', 'PORT', 'EXPIRED', 'VALID FROM', 'VALID UNTIL']
56 writer = csv.DictWriter(hostfile, fieldnames=fieldnames)
60 for host in ipcalc.Network(subnet):
63 t = threading.Thread(target=scanner, args=(host,port,))
73 t = threading.Thread(target=scanner, args=(host,port,))
82 print "waiting for %d threads to end" % threadcount