python 定时任务去检测服务器端口是否通的实例

yipeiwu_com5年前服务器

如下所示:

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 定时任务去检测服务器端口是否通的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python3实现UDP协议的服务器和客户端

利用Python中的socket模块中的来实现UDP协议,这里写一个简单的服务器和客户端。为了说明网络编程中UDP的应用,这里就不写图形化了,在两台电脑上分别打开UDP的客户端和服务端就...

python pexpect ssh 远程登录服务器的方法

python pexpect ssh 远程登录服务器的方法

使用了python中的pexpect模块,在测试代码之前,可输入python进入交互界面,输入help('pexpect'),查询是否本地含有pexpect模块。 如果没有,linux系...

深入Memcache的Session数据的多服务器共享详解

一相关介绍1.memcache + memcache的多服务器数据共享的介绍,请参见http://www.guigui8.com/index.php/archives/206.html2...

php mailer类调用远程SMTP服务器发送邮件实现方法

本文实例讲述了php mailer类调用远程SMTP服务器发送邮件实现方法。分享给大家供大家参考,具体如下: php mailer 是一款很好用的php电子邮件发送类模块,可以调用本地的...

浅析虚拟主机服务器php fsockopen函数被禁用的解决办法

一、如何禁用fsockopen()下面是两种常用的禁用fsockopen的方法。1、修改php.ini,将 disable_functions = 后加入 fsockopen 2、修改p...