-
Notifications
You must be signed in to change notification settings - Fork 0
/
pypro_Port Scanner.py
55 lines (36 loc) · 1.2 KB
/
pypro_Port 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
# **********************************************************************************************************************
# ----------------------------------------------------Port Scanner------------------------------------------------------
# **********************************************************************************************************************
import socket
import threading
from queue import Queue
target = "127.0.0.1"
queue = Queue()
open_ports = []
def port_scan(port):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((target, port))
return True
except:
return False
def fill_queue(list_of_ports):
for port in list_of_ports:
queue.put(port)
def worker():
while not queue.empty():
port = queue.get()
if port_scan(port):
print(f'port {port} is open')
open_ports.append(port)
port_list = range(1, 1025)
fill_queue(port_list)
thread_list = []
for t in range(100):
thread = threading.Thread(target=worker)
thread_list.append(thread)
for thread in thread_list:
thread.start()
for thread in thread_list:
thread.join()
print("open ports are: ", open_ports)