标签 监控 下的文章

以下来自 https://eqblog.com/whmcs-python-hon.html
http://www.hostloc.com/thread-422346-1-1.html
安装Python3 使用python3 x.py

#本脚本基于python3+方糖实现enoctus监控+微信推送
#使用方法:
#修改 sckey 为你自己的方糖KEY
#修改 pid 为你想要监控的套餐PID
#python vps.py
#香港1G pid=93


from sys import argv
from urllib import request,parse
from os import system
import datetime
sckey="xxxxxx"
pid=93

url='https://einstein.enoctus.co.uk/cart.php?a=add&pid=%s' % (pid)
try:
    flag=0
    oktime=datetime.datetime.now()
    oktime.strftime('%Y-%m-%d %H:%M:%S')
    outoftime=datetime.datetime.now()
    outoftime.strftime('%Y-%m-%d %H:%M:%S')
    while True:
        header={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36'}
        req=request.Request(url,headers=header)
        page=request.urlopen(req).read()
        if str(page).find('out of stock')>0:
            if flag>0:
                outoftime=datetime.datetime.now()
                outoftime.strftime('%Y-%m-%d %H:%M:%S')
                timeout='本轮次上货持续时间:%s' % (outoftime-oktime)
                print(timeout)
                tile='%s%s' % ('缺货提醒',timeout)
                textmod={'text':tile,'desp':url}
                textmod = parse.urlencode(textmod)
                urlsc='https://sc.ftqq.com/%s.send' % (sckey)
                req1=request.Request(url='%s%s%s' % (urlsc,'?',textmod),headers=header)
                page1=request.urlopen(req1).read()
            flag=0
            print('缺货')
        else:
            if flag==0:
                oktime=datetime.datetime.now()
                oktime.strftime('%Y-%m-%d %H:%M:%S')
                timeok='本轮缺货持续时间:%s' % (oktime-outoftime)
                print(timeok)
                tile='%s%s' % ('上货提醒',timeok)
                textmod={'text':tile,'desp':url}
                textmod = parse.urlencode(textmod)
                urlsc='https://sc.ftqq.com/%s.send' % (sckey)
                req1=request.Request(url='%s%s%s' % (urlsc,'?',textmod),headers=header)
                page1=request.urlopen(req1).read()
            flag=flag+1
            print('有货')
            if flag<3:
                tile='%s%s' % ('上货提醒',flag)
                textmod={'text':tile,'desp':url}
                textmod = parse.urlencode(textmod)
                urlsc='https://sc.ftqq.com/%s.send' % (sckey)
                req1=request.Request(url='%s%s%s' % (urlsc,'?',textmod),headers=header)
                page1=request.urlopen(req1).read()
except:
    print('脚本异常,退出')


PHP脚本

<?php
$data=file_get_contents('http://directspace.net/vps_dedicated.htm');
$available=strpos($data,"Available October 28th");
if (!$available) {
        mail ("yourmail@gmail.com", "WoW! DS2$ Available!", "DS2$ Available,GOGO!");
}
?>

<?php
$data=file_get_contents('https://directspace.net/eportal/cart.php?a=add&pid=173');
$available=strpos($data,"Out of Stock");
if (!$available) {
        mail ("yourmail@gmail.com", "WoW! DS2$ Available!", "DS2$ Available,GOGO!");
}
?>

Crontab这样写

*/5 * * * * /usr/local/php/bin/php /home/wwwroot/dsmonitor.php

这就行了,如果crontab不能执行,可能是你的系统不支持*/5这样的写法,那你就0,5,10,15,20.....55这样写
from http://www.hostloc.com/thread-32575-1-1.html

2.from http://www.hostloc.com/forum.php?mod=viewthread&tid=370961&page=2#pid4666780

<?php
    ignore_user_abort();
    set_time_limit(0);
        
    while(true)
    {
        $f = file_get_contents("http:xxxxx");
        $m = md5($f);

        $hash = file_get_contents("hash.txt");
        if($hash!=$m)
        {
            file_put_contents("hash.txt",$m);
            mail("aaa@qq.com","发生变化","内容。。。");       //mail 函数如果使用过多,有些邮箱会让他直接进垃圾邮件或者拒收,本质是调用linux的sendmail 之类发送。
                
        }
            
        echo "执行了一次<br>";
        sleep(60*15);    //休眠15分钟
            
    }