2014-01-06 10:10:36 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Tool to import and index PTR records
|
|
|
|
#
|
|
|
|
# Software is free software released under the "Modified BSD license"
|
|
|
|
#
|
|
|
|
# Copyright (c) 2013-2014 Alexandre Dulaunoy - a@foo.be
|
|
|
|
|
|
|
|
import redis
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
argParser = argparse.ArgumentParser(description='ptr-db: Import and Index PTR records')
|
|
|
|
argParser.add_argument('-r', action='append', help='Input file in IP,PTR format')
|
2014-01-11 22:02:20 +00:00
|
|
|
argParser.add_argument('-v', action='store_true', default=False, help='Output inserted PTR records')
|
2014-01-06 10:10:36 +00:00
|
|
|
args = argParser.parse_args()
|
|
|
|
|
|
|
|
def terms(host=None):
|
|
|
|
if host is None:
|
|
|
|
return False
|
|
|
|
p = host.split('.')
|
|
|
|
return p
|
|
|
|
|
|
|
|
# LevelDB backend using Redis protocol https://github.com/KDr2/redis-leveldb
|
|
|
|
r = redis.StrictRedis(host='localhost', port=8323)
|
|
|
|
|
|
|
|
if args.r:
|
|
|
|
for x in args.r:
|
2014-01-11 21:48:59 +00:00
|
|
|
with open(x, encoding='UTF-8', errors='ignore') as f:
|
|
|
|
for l in f:
|
2014-01-12 21:29:02 +00:00
|
|
|
try:
|
|
|
|
(ip, ptr) = l.rstrip().split(',')[:2]
|
|
|
|
if args.v:
|
|
|
|
print(terms(ptr))
|
|
|
|
r.set(ip,ptr)
|
|
|
|
except ValueError:
|
|
|
|
if args.v:
|
|
|
|
print("PTR tuple missing")
|
|
|
|
pass
|
2014-01-06 10:10:36 +00:00
|
|
|
else:
|
|
|
|
argParser.print_help()
|
|
|
|
exit(1)
|