You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: improve typing, logging, and privilege handling
- Add comprehensive type annotations with version-aware typing
- Implement module-specific logging throughout application
- Improve privilege detection to support sudo users (not just root UID=0)
- Enhance subprocess cleanup and asyncio cancellation handling
- Add clean exception hierarchy with NmapError base class
- Remove redundant code while maintaining full backward compatibility
Copy file name to clipboardExpand all lines: README.md
+98-39Lines changed: 98 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,29 +1,35 @@
1
1
2
-
3
2
# python3-nmap
4
3
5
4
A python 3 library which helps in using nmap port scanner. The way this tools works is by defining each nmap command into a python function making it very easy to use sophisticated nmap commands in other python scripts. Nmap is a complicated piece of software used for reconnaissance on target networks, over the years new features have been added making it more sophisticated.
6
5
7
6
With this python3-nmap we make using nmap in python very easy and painless
8
7
9
8
For example in nmap if you want to scan for common ports you would to something like this
9
+
10
10
```sh
11
-
$ nmap your-host.com --top-ports 10
11
+
nmap your-host.com --top-ports 10
12
12
```
13
+
13
14
But in this python3-nmap script you would do something like this
15
+
14
16
```py
15
17
import nmap3
16
18
nmap = nmap3.Nmap()
17
19
results = nmap.scan_top_ports("your-host.com")
18
20
# And you would get your results in json
19
21
```
22
+
20
23
You will notice each nmap command is defined as a python function/method. this make it easy to remember this in python and easily use them.
21
24
22
25
Again in nmap if you want to use the famous dns-brute script you would do something like this
26
+
23
27
```sh
24
-
$ nmap your-host.com --script dns-brute.nse
28
+
nmap your-host.com --script dns-brute.nse
25
29
```
30
+
26
31
But in this python3 script again it's very easy you just do something like this
Using this scripts is very easy, though it assumes you have nmap already installed, as it is the primary dependence required. Also this tools supports both windows and linux, it's cross platform so to say.
The following nmaps commands have been added to the following scripts
215
236
216
-
- get Nmap version details
237
+
- get Nmap version details
238
+
217
239
```python
218
240
import nmap3
219
241
nmap = nmap3.Nmap()
220
242
results = nmap.nmap_version()
221
243
```
222
-
- Nmap top port scan
244
+
245
+
- Nmap top port scan
246
+
223
247
```python
224
248
import nmap3
225
249
nmap = nmap3.Nmap()
226
250
results = nmap.scan_top_ports("your-host")
227
251
```
228
-
- Nmap Dns-brute-script( to get subdomains )
252
+
253
+
- Nmap Dns-brute-script( to get subdomains )
254
+
229
255
```python
230
256
import nmap3
231
257
nmap = nmap3.Nmap()
232
258
results = nmap.nmap_dns_brute_script("domain")
233
259
```
234
-
- Nmap list scan
260
+
261
+
- Nmap list scan
262
+
235
263
```python
236
264
import nmap3
237
265
nmap = nmap3.Nmap()
238
266
results = nmap.nmap_list_scan("your-host")
239
267
```
240
-
- Nmap Os detection
268
+
269
+
- Nmap Os detection
270
+
241
271
```python
242
272
import nmap3
243
273
nmap = nmap3.Nmap()
244
274
results = nmap.nmap_os_detection("your-host");
245
275
```
246
-
- Nmap subnet scan
276
+
277
+
- Nmap subnet scan
278
+
247
279
```python
248
280
import nmap3
249
281
nmap = nmap3.Nmap()
250
282
results = nmap.nmap_subnet_scan("your-host") #Must be root
251
283
```
252
-
- Nmap version detection
284
+
285
+
- Nmap version detection
286
+
253
287
```python
254
288
import nmap3
255
289
nmap = nmap3.Nmap()
256
290
results = nmap.nmap_version_detection("your-host") # Must be root
257
291
```
258
292
259
-
### Nmap Scanning Techniques
293
+
### Nmap Scanning Techniques
294
+
260
295
The script offers nmap scan techniques also as python function/methods
261
-
- nmap_fin_scan
296
+
297
+
- nmap_fin_scan
298
+
262
299
```python
263
300
import nmap3
264
301
nmap = nmap3.NmapScanTechniques()
265
302
result = nmap.nmap_fin_scan("192.168.178.1")
266
303
```
267
-
268
-
- nmap_idle_scan
304
+
305
+
- nmap_idle_scan
306
+
269
307
```python
270
308
import nmap3
271
309
nmap = nmap3.NmapScanTechniques()
272
310
result = nmap.nmap_idle_scan("192.168.178.1")
273
311
```
274
-
- nmap_ping_scan
312
+
313
+
- nmap_ping_scan
314
+
275
315
```python
276
316
import nmap3
277
317
nmap = nmap3.NmapScanTechniques()
278
318
result = nmap.nmap_ping_scan("192.168.178.1")
279
319
```
280
-
- nmap_syn_scan
320
+
321
+
- nmap_syn_scan
322
+
281
323
```python
282
324
import nmap3
283
325
nmap = nmap3.NmapScanTechniques()
284
326
result = nmap.nmap_syn_scan("192.168.178.1")
285
327
```
286
-
- nmap_tcp_scan
328
+
329
+
- nmap_tcp_scan
330
+
287
331
```python
288
332
import nmap3
289
333
nmap = nmap3.NmapScanTechniques()
290
334
result = nmap.nmap_tcp_scan("192.168.178.1")
291
335
```
292
-
336
+
293
337
- nmap_udp_scan
338
+
294
339
```python
295
340
import nmap3
296
341
nmap = nmap3.NmapScanTechniques()
297
342
result = nmap.nmap_udp_scan("192.168.178.1")
298
343
```
344
+
299
345
### Supporting the nmap host discovery
346
+
300
347
The script also offers support for map Added Nmap Host discovery techniques still as python function/methods
301
348
302
-
- Only port scan (-Pn)
303
-
- Only host discover (-sn)
304
-
- Arp discovery on a local network (-PR)
305
-
- Disable DNS resolution (-n)
349
+
- Only port scan (-Pn)
350
+
- Only host discover (-sn)
351
+
- Arp discovery on a local network (-PR)
352
+
- Disable DNS resolution (-n)
306
353
307
354
NmapHostDiscovery
308
355
309
-
-`def nmap_portscan_only(self, host, args=None)`
356
+
-`def nmap_portscan_only(self, host, args=None)`
357
+
310
358
```python
311
359
import nmap3
312
360
nmap = nmap3.NmapHostDiscovery()
313
361
results = nmap.nmap_portscan_only("your-host")
314
362
```
315
-
-`def nmap_no_portscan(self, host, args=None):`
363
+
364
+
-`def nmap_no_portscan(self, host, args=None):`
365
+
316
366
```python
317
367
import nmap3
318
368
nmap = nmap3.NmapHostDiscovery()
319
369
results = nmap.nmap_no_portscan("your-host")
320
370
```
321
-
-`def nmap_arp_discovery(self, host, args=None):`
371
+
372
+
-`def nmap_arp_discovery(self, host, args=None):`
373
+
322
374
```python
323
375
import nmap3
324
376
nmap = nmap3.NmapHostDiscovery()
325
377
results = nmap.nmap_arp_discovery("your-host")
378
+
326
379
```
327
-
-`def nmap_disable_dns(self, host, args=None):`
380
+
381
+
-`def nmap_disable_dns(self, host, args=None):`
382
+
328
383
```python
329
384
import nmap3
330
385
nmap = nmap3.NmapHostDiscovery()
@@ -333,7 +388,8 @@ NmapHostDiscovery
333
388
334
389
Nmap is a large tool, as you can see python3-nmap provides only things what you could say commonly used nmap features.
335
390
336
-
### Using custom nmap command line arguments.
391
+
### Using custom nmap command line arguments
392
+
337
393
As we said, the script defines each set of nmap command as python function/methods. You can also pass arguments to those methods/function thus extending your capabilities for example.
338
394
Let's say we want to scan top ports but also perform version detection .
339
395
@@ -344,6 +400,7 @@ Let's say we want to scan top ports but also perform version detection .
344
400
```
345
401
346
402
### Using the nmap vulners script to identify vulnerabilities (CVE's)
403
+
347
404
You scan the the target IP using version detection ('-sV') to get the service and, the script performs a lookup in the CVE database. The nmap vulners script is part of the default Nmap installation, so you shouldn't need to install any other packages.
348
405
349
406
```python
@@ -353,15 +410,17 @@ You scan the the target IP using version detection ('-sV') to get the service an
0 commit comments