The title says it all. The loop takes forever for the first port and then the rest of them only take one second.
import socket
target = "192.168.0.104"
try:
for port in range(52,85):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.setdefaulttimeout(1)
result=s.connect_ex((target,port))
if result == 0:
print("Port {} is open".format(port))
else:
print("Port {} is closed".format(port))
s.close()
# break
except KeyboardInterrupt:
print ('you stopp it manually')
except socket.gaierror:
print ("Cant resolve host name")
setdefaulttimeoutbefore creating the first socket object, it only affects sockets created after it is called