利用socket模块检查端口存活并邮件警报
2024-09-25 22:46:31
可以用来监控一些端口。
import socket
def check_server(addr, port):
s = socket.socket()
try:
s.connect((addr, port))
return True
except socket.error:
return False
def alert(p):
from email.mime.text import MIMEText
import smtplib
sender = "admin@qq.com"
receiver = ["admin@qq.com"]
host = 'smtp.qq.com'
passwd = 'xxxxx'
port = 465
content = '端口:%r 故障' % p
msg = MIMEText(content)
msg['From'] = "admin@qq.com"
msg['To'] =';'.join(receiver)
msg['Subject'] = "vps警报"
try:
smtp = smtplib.SMTP_SSL(host, port)
smtp.login(sender, passwd)
smtp.sendmail(sender, receiver, msg.as_string())
except Exception:
print("error")
if __name__=='__main__':
for p in [443, 2280]:
result = check_server('23.188.2.75', p)
if not result:
alert(p)
最新文章
- /MT、/MD编译选项,以及可能引起在不同堆中申请、释放内存的问题
- angular的post请求,SpringMVC后台接收不到参数值的解决方案
- ThinkPHP讲解(十)——第三方类的引入:以分页为主
- ThinkPHP验证码刷新随机数
- C++实现网格水印之调试笔记(四)—— 完成嵌入
- 【POJ】1204 Word Puzzles
- [UVA] 784 - Maze Exploration
- C#管理IIS中的站点
- Struts2 实现文件上传
- android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
- DM8168 新三板系统启动
- VMware下Linux网络配置局域网和外网访问
- linux系统无法正常启动,故障排查恢复
- Can not issue data manipulation statements with executeQuery()错误解决
- C# 监测每个方法的执行次数和占用时间(测试1)
- 008 jquery过滤选择器-----------(子元素过滤选择器)
- 【转】c#.net各种应用程序中获取文件路径的方法
- django的单元测试框架unittest、覆盖率
- mysql 分库分表(水平切割和垂直切割)
- (二)Audio子系统之new AudioRecord()