-
Notifications
You must be signed in to change notification settings - Fork 0
/
complete.py
81 lines (63 loc) · 1.85 KB
/
complete.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/python
# -*- coding: utf-8 -*-
import threading
import nmap
result = {}
lock = threading.Lock()
def scan(IP, p):
global result
global lock
p = str(p)
p = p[1:-1]
nm = nmap.PortScanner()
nm.scan(IP, p)
# print(id(nm))
tcpport = nm[IP].all_tcp()
print(tcpport)
udpport = nm[IP].all_udp()
port = set()
protocol = {}
service = {}
solfware = {}
version = {}
for tcp in tcpport:
if nm[IP]['tcp'][tcp]['state'] == 'open':
port.add(tcp)
protocol[tcp] = 'tcp'
service[tcp] = nm[IP]['tcp'][tcp]['name']
solfware[tcp] = nm[IP]['tcp'][tcp]['product']
version[tcp] = nm[IP]['tcp'][tcp]['version']
for udp in udpport:
if nm[IP]['udp'][udp]['state'] == 'open':
port.add(udp)
protocol[udp] = 'udp'
service[udp] = nm[IP]['udp'][udp]['name']
solfware[udp] = nm[IP]['udp'][udp]['product']
version[udp] = nm[IP]['udp'][udp]['version']
for p in port:
lock.acquire()
result[p] = protocol[p] + '-' + service[p] + '-' + solfware[p] + '-' + version[p]
lock.release()
def muti_scan(IP, p, thread_num):
name = []
if thread_num > 0:
times = int(len(p) / thread_num)
if times>20:
p = list(p)
for i in range(thread_num):
t = threading.Thread(target=scan, args=(IP, p[i * times:(i + 1) * times]))
t.start()
name.append(t)
# print(t)
for i in range(thread_num):
name[i].join()
if p[thread_num * times:]:
scan(IP, p[thread_num * times:])
else:
scan(IP, p)
else:
scan(IP, p)
# print(result)
if __name__ == '__main__':
scan('192.168.80.130',[0])
print(result)