mirror of
https://github.com/The-Art-of-Hacking/h4cker.git
synced 2024-12-24 06:49:23 -05:00
adding a quick python nmap example
This commit is contained in:
parent
3892b81a38
commit
49a377cd03
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 New Issue
Block a user