python判斷端口是否打開的實(shí)現(xiàn)代碼
來(lái)源:懂視網(wǎng)
責(zé)編:小采
時(shí)間:2020-11-27 14:29:38
python判斷端口是否打開的實(shí)現(xiàn)代碼
python判斷端口是否打開的實(shí)現(xiàn)代碼: 代碼如下:#!/usr/bin/env python# name IsOpen.pyimport osimport socketdef IsOpen(ip,port): s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) try: s.connect((ip,int(port))) s.shutdo
導(dǎo)讀python判斷端口是否打開的實(shí)現(xiàn)代碼: 代碼如下:#!/usr/bin/env python# name IsOpen.pyimport osimport socketdef IsOpen(ip,port): s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) try: s.connect((ip,int(port))) s.shutdo
代碼如下:
#!/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)
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
python判斷端口是否打開的實(shí)現(xiàn)代碼
python判斷端口是否打開的實(shí)現(xiàn)代碼: 代碼如下:#!/usr/bin/env python# name IsOpen.pyimport osimport socketdef IsOpen(ip,port): s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) try: s.connect((ip,int(port))) s.shutdo