I am attempting to make a simple port scanner:
socket.setdefaulttimeout(1)
try:
for port in range(lowport,highport):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#s.settimeout(1)
x = s.connect_ex((remoteServerIP, port))
if x == 0:
print "[+] Port {}: Open".format(port)
try:
s.settimeout(7)
s.send("blah")
print s.recv(100)
My question is, will the socket timeout go back to the default of (1) after the 'if' statement completes (as I believe it should and is most python) or do I need to place it explicitly in the iteration 'for' each port as I have commented out inline above.. goal being a timeout of (1) to see if the port is open, but (7) to receive the banner..