可以用来监控一些端口。

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)

最新文章

  1. /MT、/MD编译选项,以及可能引起在不同堆中申请、释放内存的问题
  2. angular的post请求,SpringMVC后台接收不到参数值的解决方案
  3. ThinkPHP讲解(十)——第三方类的引入:以分页为主
  4. ThinkPHP验证码刷新随机数
  5. C++实现网格水印之调试笔记(四)—— 完成嵌入
  6. 【POJ】1204 Word Puzzles
  7. [UVA] 784 - Maze Exploration
  8. C#管理IIS中的站点
  9. Struts2 实现文件上传
  10. android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
  11. DM8168 新三板系统启动
  12. VMware下Linux网络配置局域网和外网访问
  13. linux系统无法正常启动,故障排查恢复
  14. Can not issue data manipulation statements with executeQuery()错误解决
  15. C# 监测每个方法的执行次数和占用时间(测试1)
  16. 008 jquery过滤选择器-----------(子元素过滤选择器)
  17. 【转】c#.net各种应用程序中获取文件路径的方法
  18. django的单元测试框架unittest、覆盖率
  19. mysql 分库分表(水平切割和垂直切割)
  20. (二)Audio子系统之new AudioRecord()

热门文章

  1. HttpRequestMessage
  2. ResScope (软件资源分析)V1.94 绿色版
  3. 自动安装memcached服务端与PHP扩展Memcached
  4. (十)foreac遍历、break和countinue以及标签和switch循环
  5. Linux的文件/目录的权限
  6. CodeForces 696C PLEASE
  7. css布局理解
  8. 《JS中的面向对象技术》
  9. php基础(三)超全局变量
  10. js正则函数中test和match的区别