import socket def TelnetPort(server_ip,port): sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sk.settimeout(1) #设置超时时间 try: sk.connect((server_ip,port)) print 'OK!' except Exception: print 'Telnet Failed' sk.close() server_ip='10.16.5.19' port=873 TelnetPort(server_ip,port)