Skip to content

Instantly share code, notes, and snippets.

@Scofield-Idehen
Last active February 10, 2023 02:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Scofield-Idehen/d97c5709ac8347fd70b47f7744c75c9c to your computer and use it in GitHub Desktop.
Save Scofield-Idehen/d97c5709ac8347fd70b47f7744c75c9c to your computer and use it in GitHub Desktop.
import socket
import threading
from queue import Queue
target = "URL/IP"
queue = Queue()
ope_port = []
def scanner(port):
try:
sok = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sok.connect((target, port))
return True
except:
return False
#for port in range (1, 10):
#score = scan(port)
#if score:
#print("port {} is open".format(port))
#else:
#print("port {} is closed".format(port))
def fill_queue(list_port):
for port in list_port:
queue.put(port)
def worker():
while not queue.empty():
port = queue.get()
if scanner(port):
print("port {} is open".format(port))
ope_port.append(port)
list_port = range(1, 100)
fill_queue(list_port)
thread_list = []
for sc 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 :", ope_port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment