检查远端服务器端口是否打开

 

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)

 

posted on 2016-07-12 17:12  momingliu11  阅读(750)  评论(0编辑  收藏  举报