mirror of
https://github.com/adulau/ptr-db.git
synced 2024-12-22 00:35:57 +00:00
Basic PTR records search per IPv4 subnet
This commit is contained in:
parent
0c9a03b93f
commit
f351bb975f
1 changed files with 35 additions and 0 deletions
35
bin/ptr-search.py
Normal file
35
bin/ptr-search.py
Normal file
|
@ -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))
|
Loading…
Reference in a new issue