溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

python 定時任務(wù)去檢測服務(wù)器端口是否通的實例

發(fā)布時間:2020-08-30 17:56:03 來源:腳本之家 閱讀:208 作者:ywmack 欄目:開發(fā)技術(shù)

如下所示:

import socket
import threading
import time
 
def testconn( host , port ):
  sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  sk.settimeout(1)
  try:
    sk.connect((host,port))
    return host+" Server is "+str(port)+" connect"
  except Exception:
    return host+" Server is "+str(port)+" not connect!"
  sk.close()
 
class Test(threading.Thread):
  def __init__(self):
    pass
  def test(self):
    print testconn('172.31.32.3',22)
  def run(self):
    while True:
      #print time.strftime('%Y-%m-%d %H:%M:%S')
      self.test()
      time.sleep(1)
a=Test()
a.run()

以上這篇python 定時任務(wù)去檢測服務(wù)器端口是否通的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持億速云。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI