I'm taking Sam Bowne's online class right now and am trying to connect to a port in 1 second. I've figured out how to print the new port number but can't connect:
import socket
socket.setdefaulttimeout(2)
s=socket.socket()
i=20001
target= 'packtpub.samsclass.info'
try:
s.connect((target,int(i)))
x = s.recv(1024)
print(x)
abe = x[24:29]
print abe
finally:
print 'Knocking on second port:'
s.connect(('packtpub.samsclass.info',int(abe)))
print s.recv(1024)
s.close()
print
– Brad Figueroa Jan 13 at 21:53