File: multi_nmap_process_background.py

package info (click to toggle)
python-libnmap 0.7.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,416 kB
  • sloc: xml: 5,572; python: 4,299; makefile: 149
file content (42 lines) | stat: -rw-r--r-- 827 bytes parent folder | download
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
39
40
41
42
#!/usr/bin/env python

from time import sleep

from libnmap.process import NmapProcess


def make_nmproc_obj(targets, options):
    return NmapProcess(targets=targets, options=options)


def start_all_bg(nmprocs):
    for nmp in nmprocs:
        nmp.run_background()


def any_running(nmprocs):
    return any([nmp.is_running() for nmp in nmprocs])


def summarize(nmprocs):
    for nmp in nmprocs:
        print(
            "rc: {0} output: {1} stdout len: {2}".format(
                nmp.rc, nmp.summary, len(nmp.stdout)
            )
        )


nm_targets = []
for h in range(10):
    nm_targets.append("scanme.nmap.org")
nm_opts = "-sT"

nm_procs = [make_nmproc_obj(t, nm_opts) for t in nm_targets]
start_all_bg(nm_procs)

while any_running(nm_procs):
    print("Nmap Scan running...")
    sleep(2)

summarize(nm_procs)