mirror of
https://github.com/adulau/crl-monitor.git
synced 2024-11-25 03:27:10 +00:00
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
|
#!/usr/bin/env python
|
||
|
# -*- coding: utf-8 -*-
|
||
|
#
|
||
|
# Tool to dump IP,FP into a Redis database
|
||
|
#
|
||
|
# Software is free software released under the GNU General Public License version 3 and later
|
||
|
#
|
||
|
# Copyright (c) 2014 Alexandre Dulaunoy - a@foo.be
|
||
|
|
||
|
import fileinput
|
||
|
import argparse
|
||
|
import redis
|
||
|
import sys
|
||
|
|
||
|
argParser = argparse.ArgumentParser(description='Tool to dump IP,FP into Redis')
|
||
|
argParser.add_argument('-s', action='store_true', default=True, help='Store in Redis')
|
||
|
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('-v', action='store_true', help='Verbose output')
|
||
|
argParser.add_argument('-r', default='-', help='Read from a file, default is stdin')
|
||
|
args = argParser.parse_args()
|
||
|
|
||
|
if args.s:
|
||
|
try:
|
||
|
#Redis structure Set of (FP) per IP
|
||
|
r = redis.StrictRedis(host=args.b, port=args.p)
|
||
|
except:
|
||
|
print "Unable to connect to the Redis server"
|
||
|
sys.exit(1)
|
||
|
|
||
|
for l in fileinput.input(args.r):
|
||
|
(ip, fp) = l.split(',')
|
||
|
if args.s:
|
||
|
r.sadd(ip, fp.rstrip())
|
||
|
else:
|
||
|
sys.exit(1)
|