mirror of
https://github.com/adulau/crl-monitor.git
synced 2024-11-22 01:57:05 +00:00
JSON output added
This commit is contained in:
parent
679445ab42
commit
7a46ffd8e6
1 changed files with 28 additions and 6 deletions
|
@ -12,12 +12,14 @@ import argparse
|
|||
import redis
|
||||
import sys
|
||||
import netaddr
|
||||
import json
|
||||
|
||||
argParser = argparse.ArgumentParser(description='Tool to lookup IP for known fingerprints and X.509 subjects')
|
||||
argParser.add_argument('-b', default='127.0.0.1', help='Redis host (default is 127.0.0.1)')
|
||||
argParser.add_argument('-p', default=6379, help='Redis TCP port (default is 6379)')
|
||||
argParser.add_argument('-s', action='append', help='IPv4 subnet to lookup')
|
||||
argParser.add_argument('-v', action='store_true', help='Verbose output')
|
||||
argParser.add_argument('-o', default='readable', help='readable (default), json')
|
||||
args = argParser.parse_args()
|
||||
|
||||
if args.s is None:
|
||||
|
@ -28,18 +30,38 @@ try:
|
|||
r = redis.StrictRedis(host=args.b, port=args.p)
|
||||
except:
|
||||
print "Unable to connect to the Redis server"
|
||||
sys.exit(1)
|
||||
sys.exit(255)
|
||||
|
||||
if args.o == 'json':
|
||||
out = {}
|
||||
elif args.o == 'readable':
|
||||
pass
|
||||
else:
|
||||
print "Unknown output format"
|
||||
sys.exit(255)
|
||||
|
||||
for subnet in args.s:
|
||||
iplist = netaddr.IPNetwork(subnet)
|
||||
for ip in iplist:
|
||||
s = r.smembers(ip)
|
||||
if s:
|
||||
if args.o == 'readable':
|
||||
print ip
|
||||
for x in s:
|
||||
subjects = r.smembers(x)
|
||||
else:
|
||||
out[str(ip)] = []
|
||||
for fingerprint in s:
|
||||
subjects = r.smembers(fingerprint)
|
||||
if subjects:
|
||||
for subject in subjects:
|
||||
if args.o == 'readable':
|
||||
print " " + subject
|
||||
else:
|
||||
print " " + x
|
||||
out[str(ip)].append(subject)
|
||||
else:
|
||||
if args.o == 'readable':
|
||||
print " " + fingerprint
|
||||
else:
|
||||
out[str(ip)].append(fingerprint)
|
||||
|
||||
if args.o == 'json':
|
||||
print json.dumps(out)
|
||||
|
|
Loading…
Reference in a new issue