Python Forum
Your p“Timeout !!!!” when I enter a known good IP address when running port scanner
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Your p“Timeout !!!!” when I enter a known good IP address when running port scanner
#3
(May-13-2022, 10:35 AM)buran Wrote: Why didn't you share the code (minimal reproducible example)?

Hi Buran

I guess rookie at this but here it is below


#This program does the port scanning from 0 to 1025.

#All results will write in file.

#Errors is managed by exception and will write to file.



import concurrent.futures

import socket

import threading

import time

import sys







print_lock = threading.Lock()



ip = input("Enter the IP to scan: ") #ask user ip for scanning



f = open("scanresult.txt", "w") #open file to write results

print("Scanned IP: ", ip, file=f)





def scan(ip, port):

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

scanner.settimeout(1)

try:

scanner.connect((ip, port))

scanner.close()

with print_lock:

print(f"[{port}]" + f" is open", file=f)

except KeyboardInterrupt: #manage exception

print("\n Exiting Program !!!!", file=f)

sys.exit()

except socket.gaierror:

print("\n Host name Could Not Be Resolved !!!!", file=f)

sys.exit()

except socket.herror:

print("\n Host is not available !!!!", file=f)

sys.exit()

except socket.timeout:

print("\n TIMEOUT !!!!", file=f)

sys.exit()

except:

pass



startscan = time.time() #time when scan started

print(time.ctime(), file=f) #print date and time when scan started

with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor: #actual scanning

for port in range(1025):

executor.submit(scan, ip, port + 1)

break



endscan = time.time() #time when scan ended

print(time.ctime(), file=f) #print date and time when scan ended

print("Scan time is: ", int(endscan) - int(startscan), file=f)



f.close() #close file after writing





scan(ip, port)
Larz60+ write May-25-2022, 05:15 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

And please remove some of the empty lines. Thank you.
Reply


Messages In This Thread
RE: Your p“Timeout !!!!” when I enter a known good IP address when running port scanner - by James2000k - May-25-2022, 05:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do i listen to loopback address on my local computer, without a port billykid999 6 6,568 May-29-2023, 07:50 PM
Last Post: billykid999
  question regarding my Python port scanner script Than999 0 3,959 Jan-30-2022, 04:31 PM
Last Post: Than999
  Help with socket library for a port scanner? xanderv 1 2,961 Jan-03-2021, 10:48 PM
Last Post: Larz60+
  telnetlib timeout kerzol81 0 4,338 Sep-12-2019, 08:38 AM
Last Post: kerzol81
  Python Pexpect - SSH Timeout Nirmal 3 8,170 Oct-17-2018, 02:35 PM
Last Post: wavic
  Set request timeout for socketserver voltron 0 5,205 May-24-2018, 06:17 AM
Last Post: voltron
  how to deal with easysnmp timeout anna 0 4,354 Dec-27-2017, 12:10 PM
Last Post: anna

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020