From 49a377cd03a11b9ff986ff8c5cc458a38e88204a Mon Sep 17 00:00:00 2001 From: santosomar Date: Tue, 13 Mar 2018 18:18:55 -0400 Subject: [PATCH] adding a quick python nmap example --- python/python_nmap.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 python/python_nmap.py diff --git a/python/python_nmap.py b/python/python_nmap.py new file mode 100644 index 0000000..fe22dbe --- /dev/null +++ b/python/python_nmap.py @@ -0,0 +1,32 @@ +#!/usr/bin/python +# Author: Omar Santos @santosomar +# version 1.0 +# This is a quick demonstration on how to use the python nmap library +# * Pre-requisite: nmap python library. +# * Install it with pip install python-nmap +##################################################################### + +import sys +try: + import nmap +except: + sys.exit("[!] It looks like the nmap library is not installed in your system. You can install it with: pip install python-nmap") + +# The arguments to be processed +if len(sys.argv) != 3: + sys.exit("Please provide two arguments the first being the targets the second the ports") +addr = str(sys.argv[1]) +port = str(sys.argv[2]) + +# the scanner part + +my_scanner = nmap.PortScanner() +my_scanner.scan(addr, port) +for host in my_scanner.all_hosts(): + if not my_scanner[host].hostname(): + print("Not able to find the hostname for IP address %s") % (host) + else: + print("The hostname for IP address %s is %s") % (host, my_scanner[host].hostname()) + +#this prints the results of the scan in a csv file. +print(my_scanner.csv())