Last active
February 10, 2023 02:42
-
-
Save Scofield-Idehen/d97c5709ac8347fd70b47f7744c75c9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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