In this post I will speak about how to create Port Scanner in python 3
i will use threading to make scann faster and Socket .
First thing for every system Administrator or hacking make scan for network then found all open port for every Host.
i speak in the last post about create Ip Scanner in python .
Today we will create second script in python to make port scan on Ip and found all open port on this IP.
import threading
from queue import Queue
import time
import socket
print_lock = threading.Lock()
target = input('Enter ip Address: ')
maxport = int(input('Enter the max Number port to scan: '))
def portscan(port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
con = s.connect((target,port))
with print_lock:
print('port',port)
con.close()
except:
pass
def threader():
while True:
worker = q.get()
# Run the example job with the avail worker in queue (thread)
portscan(worker)
# completed with the job
q.task_done()
q = Queue()
for x in range(100):
t = threading.Thread(target=threader)
# classifying as a daemon, so they will die when the main dies
t.daemon = True
# begins, must come after daemon definition
t.start()
start = time.time()
for worker in range(1,maxport):
q.put(worker)
q.join()