python判断端口是否打开的实现代码
程序员文章站
2022-12-28 08:49:08
复制代码 代码如下:#!/usr/bin/env python# name isopen.pyimport osimport socketdef isopen(ip,por...
复制代码 代码如下:
#!/usr/bin/env python
# name isopen.py
import os
import socket
def isopen(ip,port):
s = socket.socket(socket.af_inet,socket.sock_stream)
try:
s.connect((ip,int(port)))
s.shutdown(2)
print '%d is open' % port
return true
except:
print '%d is down' % port
return false
if __name__ == '__main__':
isopen('1.1.1.1',800)