检测端口状态的python脚本
#!/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脚本的更多相关文章
- telnet批量检测端口状态(linux)
批量检测端口通信: 准备文件树状图 telnet.sh 脚本内容如下: 文件说明 telnet_alive.txt : 活动的端口 telnet_die.txt : 离线的端口 telnet ...
- shell 脚本检测端口状态
方法一: # cat check_port.sh #!/bin/bash cat ip.txt|while read line do /usr/bin/nc -w 1 -z $line > /d ...
- 转载大神的检测网站重定向的python脚本
#!/usr/bin/env python #coding=utf8 import sys import requests def check_for_redirects(url): try: r = ...
- 用于ViEmu的重置为试用状态的Python脚本
import winreg import shutil shutil.rmtree("C:\\Users\\Administrator\\AppData\\Local\\Identities ...
- C#实时检测端口占用情况
在TCP/IP协议中,服务端需要去监听客户端的端口,开始监听,我们需要检测使用的端口是否被占用,获取系统当前使用的所有端口号,用此端口进行匹配即可. 代码如下 internal static Bool ...
- Python与Hack之window下运行带参数的Python脚本,实现一个简单的端口扫描器
1.前提是:windows已经配置好Python的环境变量: 2.进入cmd命令行模式: **输入python命令,检测是否环境配置好:显示这样说明配置环境变量没问题 **用cd命令进入Python脚 ...
- python脚本实现集群检测和管理
python脚本实现集群检测和管理 场景是这样的:一个生产机房,会有很多的测试机器和生产机器(也就是30台左右吧),由于管理较为混乱导致了哪台机器有人用.哪台机器没人用都不清楚,从而产生了一个想法-- ...
- Python脚本控制的WebDriver 常用操作 <十九> 获取测试对象的状态
下面将使用webdriver来模拟测试中观察测试对象的状态的操作 测试用例场景 在web自动化测试中,我们需要获取测试对象的四种状态 是否显示.使用element.is_displayed()方法: ...
- Zabbix之Python脚本端口自动发现
Zabbix监控服务端口,可以手动添加配置,但是如果一个服务器上需要监控的端口数较多,那么利用Zabbix自动发现,比较高效,下面是自动发现port的Python脚本. #!/usr/bin/pyth ...
随机推荐
- slf4j,log4j,logback 初步使用
log4j,slf4j,logback简单介绍见 LogBack简易教程 Logback浅析 简单的将,slf4j是一个日志的框架,有各种日志的接口,但是并不包含实际的写日志的方法. log4j,lo ...
- PowerDesigner16建表在SQL SERVER 2008报 对象名 'sysproperties' 无效。
http://blog.itpub.net/30150152/viewspace-1454979/
- python数字图像处理(10):图像简单滤波
对图像进行滤波,可以有两种效果:一种是平滑滤波,用来抑制噪声:另一种是微分算子,可以用来检测边缘和特征提取. skimage库中通过filters模块进行滤波操作. 1.sobel算子 sobel算子 ...
- windows下怎么打开psql命令
你是直接执行的psql.exe吧? 那么需要加入数据库位置等一些参数的.Windows系统下,PostgreSQL有提供一个命令行脚本runsql.bat, 在安装目录的scripts文件夹中,一般是 ...
- [CareerCup] 8.8 Othello Game 黑白棋游戏
8.8 Othello is played as follows: Each Othello piece is white on one side and black on the other. Wh ...
- 文本模板转换工具包和 ASP.NET MVC
http://msdn.microsoft.com/zh-sg/magazine/ee291528.aspx
- Openwrt 初探
最近想研究一下Openwrt,于是开始搭建openwrt环境,虽然现在没有现成的板子,但是 可以先编译起来. openwrt的特点是基于下载 -> patch -> 编译 的一个工作模式, ...
- 学习笔记——Maven实战(一)坐标规划
坐标是什么?为什么要规划? 坐标是Maven最基本的概念,它就像每个构件的身份证号码,有了它我们就可以在数以千万计的构件中定位任何一个我们感兴趣的构件.举个最简单的例子,如果没有坐标,使用JUnit的 ...
- Mininet建立topology zoo中的拓扑
以前用Mininet建立拓扑都是在别人的代码上进行需求上的修改,这次从头开始将topology zoo(http://www.topology-zoo.org/)中的拓扑用Mininet建立,不失一般 ...
- 基于微信红包插件的原理实现android任何APP自动发送评论(已开源)
背景 地址:https://github.com/huijimuhe/postman 核心就是android的AccessibilityService,回复功能api需要23以上版本才行. 其实很像在 ...