From 49954da366a88bc4eb95180922239840c5fb1ffc Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Mon, 6 Jan 2014 11:10:36 +0100 Subject: [PATCH] Initial import of ptr-db --- README.md | 11 +++++++++++ bin/ptr-import.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 README.md create mode 100644 bin/ptr-import.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..c83b94c --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +ptr-db - PTR DNS records database +================================= + +A ptr-db is a database to store, index and lookup large set of PTR DNS records. + +Requirements +------------ + +- Python 3 +- Python [redis](https://pypi.python.org/pypi/redis/) client +- Redis [LevelDB server](https://github.com/KDr2/redis-leveldb) diff --git a/bin/ptr-import.py b/bin/ptr-import.py new file mode 100644 index 0000000..3be0a17 --- /dev/null +++ b/bin/ptr-import.py @@ -0,0 +1,37 @@ +#!/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') +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: + with open(x) as f: + for l in f: + (ip, ptr) = l.rstrip().split(',') + print (terms(ptr)) + r.set(ip,ptr) +else: + argParser.print_help() + exit(1) +#r.set("foo", "bar") +print (r.get("74.15.53.16"))