-
Notifications
You must be signed in to change notification settings - Fork 43
/
port-scanner.py
42 lines (33 loc) · 932 Bytes
/
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
import socket
import threading
from queue import Queue
target= "127.0.0.1" #Write the ip address of target you want to scan
queue=Queue()
open_ports=[]
def portscan(port):
try:
sock =socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((target, port))
return True
except:
return False
def fill_queue(port_list):
for port in port_list:
queue.put(port)
def worker():
while not queue.empty():
port=queue.get()
if portscan(port):
print("Port {} is open".format(port))
open_ports.append(port)
port_list =range(1,1024)
fill_queue(port_list)
thread_list=[]
for t in range(10):
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)