New to python, can someone add a timeout so it will return 1 if no response.
Thanks
def scan_host(host, port, r_code = 1):
try:
s = socket(AF_INET, SOCK_STREAM)
code = s.connect_ex((host, port))
if code == 0:
r_code = code
s.close()
except Exception, e:
pass
return r_code
>>149010
You're doing it wrong.
If you're doing a portscanner in Python, you want to write a little portscanning routine, then run it concurrently for a buncha ports at once, then gather the results.
http://stackoverflow.com/questions/35543955/python3-5-asyncio-tcp-scanner
>>149015
The script is only checking specific ports (e.g. 80, 81, 8080)
>>149016
You're still doing it wrong, and you still should be using async.