Skip to content

Instantly share code, notes, and snippets.

@srcecde
Last active February 6, 2017 08:19
Show Gist options
  • Save srcecde/d35b94bcefc5e4373fde04a47158e972 to your computer and use it in GitHub Desktop.
Save srcecde/d35b94bcefc5e4373fde04a47158e972 to your computer and use it in GitHub Desktop.
Demo threaded Port Scanner
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