Last active
February 6, 2017 08:19
-
-
Save srcecde/d35b94bcefc5e4373fde04a47158e972 to your computer and use it in GitHub Desktop.
Demo threaded Port Scanner
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 threading | |
from queue import Queue | |
import socket | |
server = 'hackthissite.org' | |
ip = socket.gethostbyname(server) | |
def portscan(port): | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
try: | |
con = s.connect((ip,port)) | |
with thread_lock: | |
print('Port {} is open on {}'.format(port, server)) | |
con.close() | |
except: | |
pass | |
def threader(): | |
while True: | |
worker = q.get() | |
portscan(worker) | |
q.task_done() | |
q = Queue() | |
for p in range(30): | |
t = threading.Thread(target=threader) | |
t.daemon = True | |
t.start() | |
for worker in range(1,100): | |
q.put(worker) | |
q.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment