判断端口是否开启

 import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
try:
    s.connect(('www.baidu.com',80))
    print 'Server port 80 OK!'
except Exception:
    print 'Server port 80 not connect!'
s.close()

你可能感兴趣的:(python,socket,职场,休闲)