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

作者:ywmack 时间:2021-05-18 15:09:13 

如下所示:


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()

来源:https://blog.csdn.net/ywmack/article/details/52788766

标签:python,服务器,端口
0
投稿

猜你喜欢

  • php时间不正确的解决方法

    2023-11-18 07:33:15
  • JavaScript代码着色器

    2010-01-22 15:53:00
  • Oracle中大批量删除数据的方法

    2010-07-21 13:05:00
  • Ajax实现搜索框提示功能

    2023-09-11 20:51:21
  • GO的基础知识扫盲注意事项

    2023-07-12 21:30:26
  • 36个折纸风格logo设计

    2009-09-17 13:13:00
  • 作为Web开发人员,我为什么喜欢Google Chrome浏览器

    2011-08-29 15:37:47
  • 全新极速CSS选择器引擎whiz

    2009-08-30 15:48:00
  • XHTML1.0规范:您是否为img图片标签赋予alt属性

    2009-09-21 11:11:00
  • javabean servlet jsp实现分页功能代码解析

    2023-06-13 15:21:24
  • XMLTextReader和XmlDocument读取XML文件的比较

    2008-09-05 16:04:00
  • MySQL 5.0.16的乱码问题解决方法

    2011-12-14 18:33:24
  • Python Trie树实现字典排序

    2023-08-23 02:06:10
  • selenium+python自动化测试之使用webdriver操作浏览器的方法

    2023-06-28 03:04:47
  • asp访google分页代码

    2009-07-10 13:06:00
  • 运行SQL Server的计算机间移动数据库

    2009-01-20 13:07:00
  • 超酷的js图片轮播渐变效果

    2007-10-10 20:45:00
  • PHP面向对象程序设计类的定义与用法简单示例

    2023-11-22 17:31:17
  • Python3 解释器的实现

    2023-08-09 17:08:53
  • 一些与网页密切相关的技术

    2010-09-05 21:16:00
  • asp之家 网络编程 m.aspxhome.com