Python探测主机端口是否存活

#!/usr/bin/python3
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('10.10.130.111',8080))

if 0 == result:
   print("Port is open")
else:
   print("Port is not open,return code:%s" % result)

  

posted @ 2017-07-06 22:39  lixin[at]hitwh  阅读(3816)  评论(0编辑  收藏  举报