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

相关文章

Python3 jupyter notebook 服务器搭建过程

1. jupyter notebook 安装 •创建 jupyter 目录 mkdir jupyter cd jupyter/ •创建独立的 Python3...

使用Python实现简单的服务器功能

socket接口是实际上是操作系统提供的系统调用。socket的使用并不局限于Python语言,你可以用C或者Java来写出同样的socket服务器,而所有语言使用socket的方式都类...

单台服务器的PHP进程之间实现共享内存的方法

开发人员要想使php进程实现共享内存的读写,首先就要支持IPC函数,即php编译安装时指定:--enable-shmop  与--enable-sysvsem 两个选项。 IP...

无法在发生错误时创建会话,请检查 PHP 或网站服务器日志,并正确配置 PHP 安装(win+linux)

windows下的解决方法:通过查找php.ini的session.save_path = ""的路径,检查是否存在这个目录或这个目录是否有everyone或Authenticated...

php5.2的curl-bug 服务器被php进程卡死问题排查

php5.2的curl-bug 服务器被php进程卡死问题排查

前几天东政同学反馈说Linode服务器快卡死了,今天有时间排查了一下具体原因,最终原因稍微有点悲壮:file_get_contents没有设置超时时间,加上我用的php5.2关于curl...