python判断端口是否打开的实现代码
(编辑:jimmy 日期: 2024/11/17 浏览:3 次 )
复制代码 代码如下:
#!/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)
#!/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)
下一篇:Python实现的金山快盘的签到程序