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

yipeiwu_com6年前服务器

如下所示:

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设计】。

相关文章

利用Python中SocketServer 实现客户端与服务器间非阻塞通信

利用SocketServer模块来实现网络客户端与服务器并发连接非阻塞通信。 首先,先了解下SocketServer模块中可供使用的类: BaseServer:包含服务器的核心功能与混合...

Pycharm连接远程服务器并实现远程调试的实现

Pycharm连接远程服务器并实现远程调试的实现

当需要远程办公时,使用pycharm远程连接服务器时必要的。 PyCharm提供两种远程调试(Remote Debugging)的方式: 配置远程的解释器(remote inter...

python 从远程服务器下载日志文件的程序

复制代码 代码如下:import osimport sysimport ftplibimport socket #####################################...

Python代码实现http/https代理服务器的脚本

一个几百行代码做出http/https代理服务器的脚本,启动即可做http https透明代理使用 python proxy.py 8992 使用非阻塞io模式,性能还可以。 可以和浏览...

python实现获取客户机上指定文件并传输到服务器的方法

本文实例讲述了python实现获取客户机上指定文件并传输到服务器的方法。分享给大家供大家参考。具体分析如下: 该程序实现了,把目标机器的某个目录(可控)的所有的某种类型文件(可控)全部获...