-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPort_scanner.py
More file actions
45 lines (38 loc) · 1.17 KB
/
Port_scanner.py
File metadata and controls
45 lines (38 loc) · 1.17 KB
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
import socket
import threading
import time
ip = '127.0.0.1'
thred_array = []
closed_array = []
def port_scan(ip, port_name):
global thred_array, closed_array
sockt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockt.settimeout(0.01)
try:
connect = sockt.connect((ip, port_name))
print(f'Port:\033[32m {port_name}\033[0m is\033[32m live \033[0m')
thred_array.append(port_name)
sockt.close()
except:
print(f'Port: {port_name} is\033[31m down \033[0m\n')
closed_array.append(port_name)
sockt.close()
def open_ports():
global thred_array
print('Opened ports:')
print(thred_array)
print(f'Открытых портов: {len(thred_array)}\n')
def closed_ports():
global closed_array
closed_array.sort()
print('Closed sorted ports: ')
print(closed_array)
print(f'Закрытых портов: {len(closed_array)}')
for p_name in range(1,64001):
thred = threading.Thread(target=port_scan, args=(ip, p_name))
thred.start()
time.sleep(3)
sec_thred = threading.Thread(target=open_ports)
sec_thred.start()
thrd_th = threading.Thread(target= closed_ports)
thrd_th.start()