From f351bb975f278704234f9ca1d69ad878edbd4df1 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Sat, 11 Jan 2014 23:20:36 +0100 Subject: [PATCH] Basic PTR records search per IPv4 subnet --- bin/ptr-search.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 bin/ptr-search.py diff --git a/bin/ptr-search.py b/bin/ptr-search.py new file mode 100644 index 0000000..a3a8c70 --- /dev/null +++ b/bin/ptr-search.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Tool to query an IPv4 subnet for existing 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 +import netaddr + +argParser = argparse.ArgumentParser(description='ptr-db: Search PTR records') +argParser.add_argument('-s', action='append', help='IPv4 subnet to lookup') +argParser.add_argument('-v', action='store_true', default=False, help='Dump queries') +args = argParser.parse_args() + +if args.s is None: + argParser.print_help() + exit(1) + + +# LevelDB backend using Redis protocol https://github.com/KDr2/redis-leveldb +r = redis.StrictRedis(host='localhost', port=8323) + +for subnet in args.s: + iplist = netaddr.IPNetwork(subnet) + for ip in iplist: + ptr = r.get(ip) + if ptr is not None: + print (str(ip)+","+str(r.get(ip), 'utf-8')) + else: + print (str(ip))