虽然如今选择VPS、服务器并不是那么困难,但是还是有些服务商提供的特价或者稀缺VPS、服务器得到用户抢购的。且大部分海外服务商由于时差或者不确定更新因素,我们往往会错过一些时间。因为大部分主机商都会采用WHMCS面板的,所以在这篇文章中蜗牛整理出来这个可以利用Python监控利用Server酱微信推送通知。
这个脚本来自这里(https://github.com/uselibrary/Server_Status/),蜗牛测试后是可以使用的,然后加上对应的ID获取,这样不至于每次需要编辑ID文件。
第一、脚本地址
文件:https://raw.githubusercontent.com/laobuluo/Python-VPS/master/whmwx.py
脚本代码:
# !/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys
from sys import argv
from urllib import request
import requests
from datetime import datetime
timeout = 10
time = datetime.now().strftime(\'%Y-%m-%d %H:%M:%S\')
key = \'Server酱申请KEY\'
title = \"WHMCS面板VPS上货监测\"
pid = sys.argv[1]
#需要WHMCS面板对应监控的URL
url = \'https://www.example.com/cart.php?a=add&pid=\'+str(pid)
head = {
\'Connection\': \'Keep-Alive\',
\'Accept\': \'text/html, application/xhtml+xml, */*\',
\'Accept-Language\': \'en-US,en;q=0.8,zh-Hans-CN;q=0.5,zh-Hans;q=0.3\',
\'User-Agent\': \'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko\'
}
try:
req = request.Request(url, headers=head)
response = request.urlopen(req, timeout=timeout)
html = response.read()
html = html.decode(\"utf-8\").lower()
str=\"out of stock\"
if str in html:
print(\"缺货\" + \"\\n\" + time)
else:
print(\"不缺货\" + \"\\n\" + time)
content = \"当前上货啦~\" + \"\\n\" + time + \"\\n\" + url
payload = {
\'text\': title,
\'desp\': content
}
fturl = \'https://sc.ftqq.com/{}.send\'.format(key)
requests.post(fturl, params=payload, timeout=timeout)
except Exception:
print(\"Error\" + \"\\n\" + time)
这里我们需要去Server酱(http://sc.ftqq.com/)申请KEY,以及我们需要修改需要监控服务商的URL,PID不用填写。需要确保是使用的WHMCS面板才可以。
第二、如何使用
python whmwx.py 123
这里需要时Python3环境的,如果没有可以参考\"Linux CentOS7升级和安装Python3.6.5软件版本教程\"和\"Ubuntu16.04系统快速安装Python3.6环境且设置默认运行\"安装。如果执行过程中有报错,需要检查是不是缺少安装某些组件支持。
赞(0)


