1+ import nmap3
2+ import PySimpleGUI as sg #use for GUI creating
3+ from pprint import pformat #dict to str
4+
5+ #====Initialize====
6+ nmap_basics = nmap3 .Nmap ()
7+ nmap_scatec = nmap3 .NmapScanTechniques ()
8+ nmap_basics_submits = [ #7 Submits
9+ sg .Text ('Basic Nmap functions' ),
10+ sg .Submit ("Nmap Version" ,key = "nmap_version" ),
11+ sg .Submit ("Scan Top Ports" ,key = "scan_top_ports" ),
12+ sg .Submit ("DNS Brute Script" ,key = "dns_brute_script" ),
13+ sg .Submit ("List Scan" ,key = "list_scan" ),
14+ sg .Submit ("OS Detection" ,key = "os_detection" ),
15+ sg .Submit ("Subnet Scan" ,key = "subnet_scan" ),
16+ sg .Submit ("Nmap Version Detection" ,key = "nmap_version_detection" ),
17+ ]
18+ nmap_scatec_submits = [ #6 Submits
19+ sg .Text ('NmapScanTechniques Functions' ),
20+ sg .Submit ("FIN Scan" ,key = "fin_scan" ),
21+ sg .Submit ("Idle Packet" ,key = "idle_scan" ),
22+ sg .Submit ("Ping Scan" ,key = "ping_scan" ),
23+ sg .Submit ("SYN Scan" ,key = "syn_scan" ),
24+ sg .Submit ("TCP Scan" ,key = "tcp_scan" ),
25+ sg .Submit ("UDP Scan" ,key = "udp_scan" )
26+ ]
27+ sg .theme ("LightGreen5" )
28+ layout = [
29+ [sg .Text ("[Required]Destination(IPv4): " ),sg .InputText ("127.0.0.1" ,key = "ipv4_dst" )],
30+ [sg .Text ("[Recommended]First: connectivity test by ping scan" )],
31+ nmap_basics_submits ,
32+ nmap_scatec_submits ,
33+ [sg .Text ('Statement' ),sg .Output (key = 'statement' ,size = (50 ,1 )),sg .Cancel ("Wanna Cancel" ,key = "cancel" )],
34+ [sg .Text ('Results' ),sg .Output (key = 'results' ,size = (100 ,15 ))],
35+ ]
36+ window = sg .Window (title = 'python3-nmap GUI for Beginners' , layout = layout )
37+
38+ #====Basic Nmap 7 functions====
39+ def nmap_version (): #ping_request
40+ window ['statement' ].update ("Ready!" )
41+ results = nmap_basics .nmap_version ()
42+ results = pformat (results ,compact = True ) #dict to str
43+ window ['statement' ].update ("Completed!" )
44+ window ['results' ].update (results )
45+
46+ def scan_top_ports (dst ):#TCP Port Scan(Well-known)
47+ window ['statement' ].update ("Ready!" )
48+ results = nmap_basics .scan_top_ports (dst )
49+ results = pformat (results ,compact = True ) #dict to str
50+ window ['statement' ].update ("TCP Port Scan Results(SA: open,RA: filtered)" )
51+ window ['results' ].update (results )
52+
53+ def dns_brute_script (dst ):
54+ window ['statement' ].update ("Ready!" )
55+ results = nmap_basics .nmap_dns_brute_script ("domain" )
56+ results = pformat (results ,compact = True ) #dict to str
57+ window ['statement' ].update ("DNS_Brute_Script Result" )
58+ window ['results' ].update (results )
59+
60+ def list_scan (dst ):
61+ window ['statement' ].update ("Ready!" )
62+ results = nmap_basics .nmap_list_scan (dst )
63+ results = pformat (results ,compact = True ) #dict to str
64+ window ['statement' ].update ("Nmap List Scan Results" )
65+ window ['results' ].update (results )
66+
67+ def os_detection (dst ): #Must be root
68+ window ['statement' ].update ("Ready!" )
69+ results = nmap_basics .nmap_os_detection (dst )
70+ results = pformat (results ,compact = True ) #dict to str
71+ window ['statement' ].update ("OS Detection Results" )
72+ window ['results' ].update (results )
73+
74+ def subnet_scan (dst ):#Must be root
75+ window ['statement' ].update ("Ready!" )
76+ results = nmap_basics .subnet_scan (dst )
77+ results = pformat (results ,compact = True ) #dict to str
78+ window ['statement' ].update ("Subnet Scan Results" )
79+ window ['results' ].update (results )
80+
81+ def nmap_version_detection (dst ):
82+ window ['statement' ].update ("Ready!" )
83+ results = nmap_basics .nmap_version_detection (dst )# will add an argument[args="--script vulners --script-args mincvss+5.0"]
84+ results = pformat (results ,compact = True ) #dict to str
85+ window ['statement' ].update ("Nmap Version Detection Results" )
86+ window ['results' ].update (results )
87+
88+ #====NmapScanTechniques 6 functions=====
89+ def fin_scan (dst ):
90+ window ['statement' ].update ("Ready!" )
91+ results = nmap_scatec .nmap_fin_scan (dst )
92+ results = pformat (results ,compact = True ) #dict to str
93+ window ['statement' ].update ("FIN Scan Result" )
94+ window ['results' ].update (results )
95+
96+ def idle_scan (dst ):
97+ window ['statement' ].update ("Ready!" )
98+ results = nmap_scatec .nmap_idle_scan (dst )
99+ results = pformat (results ,compact = True ) #dict to str
100+ window ['statement' ].update ("Idle Scan Result" )
101+ window ['results' ].update (results )
102+
103+ def ping_scan (dst ):
104+ window ['statement' ].update ("Ready!" )
105+ results = nmap_scatec .nmap_ping_scan (dst )
106+ results = pformat (results ,compact = True ) #dict to str
107+ window ['statement' ].update ("ping reply Results" )
108+ window ['results' ].update (results )
109+
110+ def syn_scan (dst ):
111+ window ['statement' ].update ("Ready!" )
112+ results = nmap_scatec .nmap_syn_scan (dst )
113+ results = pformat (results ,compact = True ) #dict to str
114+ window ['statement' ].update ("SYN Scan Results" )
115+ window ['results' ].update (results )
116+
117+ def tcp_scan (dst ):
118+ window ['statement' ].update ("Ready!" )
119+ results = nmap_scatec .nmap_tcp_scan (dst )
120+ results = pformat (results ,compact = True ) #dict to str
121+ window ['statement' ].update ("TCP Scan Results" )
122+ window ['results' ].update (results )
123+
124+ def udp_scan (dst ):#Must be root
125+ window ['statement' ].update ("Ready!" )
126+ results = nmap_scatec .nmap_udp_scan (dst )
127+ results = pformat (results ,compact = True ) #dict to str
128+ window ['statement' ].update ("UDP Scan Results" )
129+ window ['results' ].update (results )
130+
131+ #====Operate GUI ====
132+ while True :
133+ event , values = window .read ()
134+ dst = values ["ipv4_dst" ]
135+
136+ #[Execute]: Click "x Button" on upper right, GUI is Closed
137+ if event == sg .WIN_CLOSED :
138+ break
139+ #[Execute]: Click "Wanna Cancel Button", GUI is not Closed but STOP Execute something
140+ if event == "cancel" :
141+ continue
142+ #[Execute] Basic Nmap 7 functions
143+ if event == "nmap_version" :
144+ nmap_version ()
145+ if event == "scan_top_ports" :
146+ scan_top_ports (dst )
147+ if event == "dns_brute_script" :
148+ dns_brute_script (dst )
149+ if event == "list_scan" :
150+ list_scan (dst )
151+ if event == "os_detection" :
152+ os_detection (dst )
153+ if event == "subnet_scan" :
154+ subnet_scan (dst )
155+ if event == "nmap_version_detection" :
156+ nmap_version_detection (dst )
157+ #[Execute] NmapScanTechniques 6 functions=====
158+ if event == "fin_scan" :
159+ fin_scan (dst )
160+ if event == "idle_scan" :
161+ idle_scan (dst )
162+ if event == "ping_scan" :
163+ ping_scan (dst )
164+ if event == "syn_scan" :
165+ syn_scan (dst )
166+ if event == "tcp_scan" :
167+ tcp_scan (dst )
168+ if event == "udp_scan" :
169+ udp_scan (dst )
170+ window .close ()
171+
172+ #PySimpleGUI Reference: https://github.com/PySimpleGUI/PySimpleGUI
173+ #python3-nmap Reference: https://pypi.org/project/python3-nmap/
174+ #Nmap Reference: https://nmap.org/download.html
0 commit comments