激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - Python實現個人微信號自動監控告警的示例

Python實現個人微信號自動監控告警的示例

2021-07-30 00:10Sunny_Future Python

今天小編就為大家分享一篇Python實現個人微信號自動監控告警的示例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

wechat_sender 是基于 wxpy 和 tornado 實現的一個可以將你的網站、爬蟲、腳本等其他應用中各種消息 (日志、報警、運行結果等) 發送到微信的工具。

運行環境

Python 2.7 及以上 Python 3 及以上

實現過程

安裝 pip 工具

  1. [root@server1 ~]# wget https://bootstrap.pypa.io/get-pip.py
  2. [root@server1 ~]# python get-pip.py

Python實現個人微信號自動監控告警的示例

pip 安裝模塊

  1. ##安裝依賴軟件
  2. [root@server1 ~]# yum install -y gcc python-devel
  3. ##安裝
  4. [root@server1 ~]# pip install wechat_sender

Web登錄微信發送消息

安裝web服務器

  1. [root@server1 ~]# yum install -y httpd
  2. [root@server1 ~]# systemctl start http
  3. [root@server1 ~]# systemctl stop firewalld
  1. [root@server1 ~]# cat /var/www/html/index.html
  2. <html>
  3. <head><meta http-equiv="refresh" content="2"></head>
  4. <style>
  5. body {
  6. width: 35em;
  7. margin: 0 auto;
  8. font-family: Tahoma, Verdana, Arial, sans-serif;
  9. }
  10. </style>
  11. <body>
  12. <img src="/qr.png">
  13. </body>
  14. </html>

python腳本代碼

  1. [root@server1 ~]# cat /var/www/html/sender.py
  2. #!/bin/bash/env python
  3. #coding:utf-8
  4.  
  5. from wxpy import *
  6. from wechat_sender import *
  7. from wechat_sender import Sender
  8.  
  9. #bot = Bot() ##windows直接掃
  10. #下面這個是服務器版(Linux)
  11. #bot = Bot(qr_path="qr.png")
  12. #避免重復登錄重復掃二維碼
  13. bot = Bot(qr_path="qr.png",cache_path=True)
  14. ##通過文件助手給登錄的微信號發消息
  15. bot.file_helper.send('Hello world!')

web登錄微信

  1. ##執行python腳本,占用終端,web登錄后會有提示
  2. [root@server1 ~]# cd /var/www/html/
  3. [root@server1 ~]# python sender.py
  4. Getting uuid of QR code.
  5. Downloading QR code.
  6. xdg-open: no method available for opening 'qr.png'
  7. Please scan the QR code to log in.

另一方面,打開瀏覽器輸入 ip or localhost,微信掃一掃

Python實現個人微信號自動監控告警的示例

微信登錄后,終端釋放,提示成功,消息同時發送,并且web二維碼失效

  1. Login successfully as someone

微信點擊確認

Python實現個人微信號自動監控告警的示例

查看手機助手,消息已經收到!

Python實現個人微信號自動監控告警的示例

監控80端口,自動告警

若是web服務也是80端口,請先登錄成功后,如下操作。

shell腳本

  1. [root@server1 ~]# cat /var/www/html/check_80.sh
  2. #!/bin/sh
  3.  
  4. x=$(netstat -antlp | grep '\<80\>'|awk -F' ' '{print $4}'|awk -F: '{print $2}')
  5.  
  6. if [ "$x" != 80 ];then
  7. python /var/www/html/check_80.py &
  8. else
  9. python /var/www/html/check01_80.py &
  10. fi
  11. ##添加執行權限
  12. [root@server1 ~]# chomd +x /var/www/html/check_80.sh
  1. [root@server1 ~]# cat /var/www/html/check01_80.py
  2. #!/bin/sh/env python
  3. #coding:utf-8
  4.  
  5. from wxpy import *
  6. from wechat_sender import *
  7. from wechat_sender import Sender
  8.  
  9. bot = Bot(qr_path="qr.png",cache_path=True)
  10. ##通過文件助手給登錄的微信號發消息
  11. bot.file_helper.send('port 80 nice!')
  1. [root@server1 ~]# cat /var/www/html/check_80.py
  2. #!/bin/sh/env python
  3. #coding:utf-8
  4.  
  5. from wxpy import *
  6. from wechat_sender import *
  7. from wechat_sender import Sender
  8.  
  9. bot = Bot(qr_path="qr.png",cache_path=True)
  10. ##通過文件助手給登錄的微信號發消息
  11. bot.file_helper.send('port 80 error!')
  1. [root@server1 ~]# cat /mnt/check.sh
  2. #!/bin/sh
  3.  
  4. cd /var/www/html
  5. sh check_80.sh
  1. [root@server1 ~]# chmod +x /mnt/check.sh

測試腳本

1.httpd 服務開啟時,端口 80 存在

  1. [root@server1 ~]# sh /mnt/check.sh

Python實現個人微信號自動監控告警的示例

2.httpd 服務關閉后,端口 80 不存在

  1. [root@server1 ~]# systemctl stop httpd
  1. [root@server1 ~]# sh /mnt/check.sh

Python實現個人微信號自動監控告警的示例

3.httpd 服務再次開啟,端口 80 存在

  1. [root@server1 ~]# systemctl start httpd
  1. [root@server1 ~]# sh /mnt/check.sh

Python實現個人微信號自動監控告警的示例

添加任務計劃自動監控進行告警

  1. [root@server1 ~]# crontab -e
  2. * 1 * * * sh /mnt/check.sh

投入使用

添加任務計劃后,妥善修改腳本,避免頻繁告警。

以上這篇Python實現個人微信號自動監控告警的示例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持我們。

原文鏈接:https://blog.csdn.net/Sunny_Future/article/details/81545327

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 一级做受毛片免费大片 | 亚洲成人在线免费观看 | 国产美女的小嫩bbb图片 | 热99在线视频 | 在线日韩亚洲 | 久久精品国产99国产精品澳门 | 色中色综合网 | 欧美片一区二区 | 久久久久久麻豆 | 在线观看免费毛片视频 | 免费色片| 黄色av免费电影 | 99久久超碰中文字幕伊人 | 亚洲精品在线观看网站 | 欧美日韩亚洲在线 | 免费国产成人高清在线看软件 | 日韩视频在线一区二区三区 | 99久久精品免费看国产小宝寻花 | 欧美一级黄| 在线观看国产网站 | 最新中文字幕日本 | 国产精品久久久久国产精品三级 | 亚洲精品成人18久久久久 | 成人免费毛片明星色大师 | 狠狠干狠狠操 | 日韩视频一区二区三区四区 | 欧美黄色看 | 久久久久久久久成人 | 欧美一区二区三区中文字幕 | 欧美日韩亚洲在线观看 | 可以免费看的av | 一区二区三区欧美视频 | 国产精品午夜在线 | 强伦女教师视频 | 久久精品视频国产 | 亚洲一区二区国产 | 久久密 | 99最新地址 | chengrenzaixian | 伦理三区 | 在线观看av国产一区二区 |