2014-12-31 15:42:46 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2015-02-02 06:52:49 +00:00
|
|
|
# Tool to dump IP,set(FP) and FP,set(IP) into a Redis database
|
2014-12-31 15:42:46 +00:00
|
|
|
#
|
|
|
|
# Software is free software released under the GNU General Public License version 3 and later
|
|
|
|
#
|
2015-02-02 06:52:49 +00:00
|
|
|
# Copyright (c) 2015 Alexandre Dulaunoy - a@foo.be
|
2014-12-31 15:42:46 +00:00
|
|
|
|
|
|
|
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:
|
|
|
|
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:
|
2015-02-02 06:52:49 +00:00
|
|
|
cfp = fp.rstrip()
|
|
|
|
r.sadd(ip, cfp)
|
|
|
|
r.sadd("s:"+cfp, ip)
|
2014-12-31 15:42:46 +00:00
|
|
|
else:
|
|
|
|
sys.exit(1)
|