Skip to content

Commit

Permalink
Python Port Scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
akumar0709 authored Oct 2, 2020
1 parent ea7c70f commit 2fd54c6
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions port scanner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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)

0 comments on commit 2fd54c6

Please sign in to comment.