mirror of
https://github.com/The-Art-of-Hacking/h4cker
synced 2024-11-22 02:43:02 +00:00
adding a quick python nmap example
This commit is contained in:
parent
3892b81a38
commit
49a377cd03
1 changed files with 32 additions and 0 deletions
32
python/python_nmap.py
Normal file
32
python/python_nmap.py
Normal file
|
@ -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())
|
Loading…
Reference in a new issue