0% found this document useful (0 votes)
2 views

Python Port Scaner Project

This document is a Python script that performs a port scan on a specified host using multithreading for efficiency. It prompts the user for a host, resolves its IP address, and checks for open ports from 1 to 1025. The script reports the open ports and the total time taken for the scan.

Uploaded by

mortscitravis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python Port Scaner Project

This document is a Python script that performs a port scan on a specified host using multithreading for efficiency. It prompts the user for a host, resolves its IP address, and checks for open ports from 1 to 1025. The script reports the open ports and the total time taken for the scan.

Uploaded by

mortscitravis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import sys

import socket

from time import time

from datetime import datetime

import threading

from queue import Queue

socket.setdefaulttimeout(0.25)

print_lock = threading.Lock()

target = input('Enter a host to scan: ')

try:

t_IP = socket.gethostbyname(target)

except socket.gaierror:

print("Host name could not be resolved")

sys.exit()

except socket.error:

print("Couldn't connect to server")

sys.exit()

else:

print('Starting scan on host: ', t_IP)

def portscan(port):

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:

con = s.connect((t_IP, port))

with print_lock:

print(port, 'is open')

con.close()

except:
pass

def threader():

while True:

worker = q.get()

portscan(worker)

q.task_done()

q = Queue()

startDate = datetime.today()

startTime = time()

print("Scan Started: ", startDate)

for x in range(100):

t = threading.Thread(target=threader)

t.daemon = True

t.start()

for worker in range(1, 1026):

q.put(worker)

q.join()

print('Scan Ended : ',datetime.today())

print('Time taken:', time() - startTime)

You might also like