-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_nmap.py
More file actions
38 lines (27 loc) · 911 Bytes
/
Copy pathmy_nmap.py
File metadata and controls
38 lines (27 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#we add nmap library
import nmap
#Create object
scanner = nmap.PortScanner()
#try except for error message
try:
#Target IP address
ip = input(">> ")
#Scan ip and from 0 to 1000 and -sS: TCP SYN scan, -sV: Version
scanner.scan(ip, arguments = '-sS -sV')
#we check host ip state
print(ip,":",scanner[ip].state())
#we create loop and port state open
for port in scanner[ip]['tcp'].keys() :
#Protocol name like ftp, http ...
name = scanner[ip]['tcp'][port]['name']
#Version name like 2.2.8
version = scanner[ip]['tcp'][port]['version']
#Product name like Apache httpd
product = scanner[ip]['tcp'][port]['product']
#State
state = scanner[ip]['tcp'][port]['state']
#finally we print
print(port,state,name,product,version)
#if we wrong the anything this except print it.
except Exception as e:
print("Error :",e)