检测端口状态的python脚本
2016-11-14 10:52
218 查看
#!/usr/bin/env python import os,subprocess,socket,time,sys from urllib import urlencode from socket import gethostname def check_port(): port = [8091,8080] failed_port = [] for _each_port in port: #print i try: sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sk.settimeout(2) sk.connect(('localhost',_each_port)) sk.close now = time.strftime("%Y-%m-%d %H:%M:%S") tt = "check port success!" logfile = "/home/op/check.log" f = open(logfile,'a+') f.write(now + " " + tt + "\n") f.close() except socket.error: failed_port.append(_each_port) for _each_port in failed_port: name = gethostname() message = "host: %s port: %d down" %(name, _each_port) tel = [电话号码] for _each_phone in tel: data = { "phone": _each_phone, "message": message } command='curl "http://"短信接口ip":8080/message.php?%s"' %(urlencode(data)) print command ck = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) std_ok, std_err = ck.communicate(input=None) #print std_ok #print std_err if __name__ == '__main__': check_port()
相关文章推荐
- 使用python检测手机QQ在线状态的脚本代码
- python端口检测和ping检测脚本
- 使用python检测手机QQ在线状态的脚本代码
- python检测QQ在线状态脚本
- python检测远程主机的端口状态
- Python 脚本学习(三),日志分析脚本,文件差异对比,HTTP状态检测
- python检测mysql状态脚本--参考
- C#如何检测网络端口连接的状态
- MYSQL 数据库状态检查脚本(Python版)
- python脚本检测linux进程是否运行
- linux下利用shell脚本自动检测服务状态并自动恢复服务
- 用bash脚本文件检测主机上的端口是否已经开启
- Linux下检测Apache运行状态的脚本
- 一个监视CSDN论坛押宝游戏状态的python脚本
- python脚本监控网站状态 推荐
- python 多线程检测同网段主机在线状态
- python写的用WMI检测windows系统信息的脚本
- 简单检测服务器信息的脚本(Python)
- 一个检测MySQL状态的脚本
- 轻松接触一个检测MySQL状态的脚本