-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnmap-mp-scanner.py
61 lines (48 loc) · 1.94 KB
/
nmap-mp-scanner.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#nmap-mp-scanner is multiprocess scanner, which achieve parallelism efficiently. With 40 processes, all ports -p- scan with -sV was completed in less the 24 hours for 800 hosts using digitalOcean VPS.
# Multiprocessing > Multithreading
import urllib3
import multiprocessing.pool
import time
import os
number_of_processes=30
nmap_directory_name="nmap"
def runScan(target):
print("Target scanning: "+target)
result = os.popen('nmap -Pn -T4 -sV -p- -oX '+nmap_directory_name+'/nmap-' + target + ".xml "+target).read().splitlines()
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
if __name__ == "__main__":
print(" ***** nmap multiprocess Scanner Started ***** ")
if not os.path.exists(nmap_directory_name):
os.makedirs(nmap_directory_name)
input_file = open("input.txt", "r")
targets = input_file.readlines()
input_file.close()
targets = [x.strip() for x in targets]
if len(targets) < number_of_processes:
number_of_processes = len(targets)
index = 0
processes = []
for i in range(number_of_processes):
processes.append(multiprocessing.Process(target=runScan,args=(targets[index],)))
index+=1
for p in processes:
p.start()
more_loop = True
while more_loop:
time.sleep(5)
for i in range(0,number_of_processes) :
if processes[i].is_alive():
processes[i].join(1)
#print("jobs is not finished")
else:
if index >= len(targets):
for p in processes:
p.join()
more_loop = False
break
processes[i] = multiprocessing.Process(target=runScan,args=(targets[index],))
processes[i].start()
index+=1
print("Pool completed execution!!!")
print("Exiting main thread.")
exit(0)