Created
January 19, 2016 09:54
-
-
Save flyte/7d3936eb72c3570618d7 to your computer and use it in GitHub Desktop.
Port scan a host and save the results to a CouchDB document.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from collections import OrderedDict | |
import couchdbkit as cdb | |
import argparse | |
import nmap | |
import sys | |
db = None | |
p = argparse.ArgumentParser() | |
args = OrderedDict([ | |
("host", {}), | |
("--db_uri", {"default": "http://127.0.0.1:5984"}) | |
]) | |
for key, params in args.items(): | |
p.add_argument(key, **params) | |
class HostScan(cdb.Document): | |
datetime = cdb.DateTimeProperty() | |
scan = cdb.DictProperty() | |
if __name__ == "__main__": | |
args = p.parse_args() | |
try: | |
print "Connecting to DB.." | |
s = cdb.Server(uri=args.db_uri) | |
print "Getting or creating 'snoopback' database.." | |
db = s.get_or_create_db("snoopback") | |
nm = nmap.PortScanner() | |
print "Scanning %s.." % args.host | |
nm.scan(args.host, arguments="-sV") | |
print "Saving results to db.." | |
HostScan.set_db(db) | |
scan = HostScan( | |
datetime=datetime.now(), | |
scan=nm[args.host] | |
) | |
scan.save() | |
except Exception, e: | |
print "Exception: %s" % e | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment