做一只天地间的蝼蚁。。。
又有何不可呢?

自动检查是否被Q脚本.发送消息到微信通知

需要去server酱注册一下 key.

网址 http://sc.ftqq.com

代码:

<?php
set_time_limit(0);
ignore_user_abort(1);
// 多个
$ip = [
'IP地址:端口',
'IP地址:端口',
];

// server酱Key
$skey = 'key';

$err = '';
foreach ($ip as $key => $value) {
$arr = explode(':', $value);
$domain = $arr[0];
$port = $arr[1];
// 国内
$check1 = 'https://www.toolsdaquan.com/toolapi/public/ipchecking/' . $domain . '/' . $port;
$data1 = curls($check1);
$data1 = json_decode($data1, true);
// 国外
$check2 = 'https://www.toolsdaquan.com/toolapi/public/ipchecking2/' . $domain . '/' . $port;
$data2 = curls($check2);
$data2 = json_decode($data2, true);

// 国内
if ($data1['icmp'] != 'success' && $data2['outside_icmp'] == 'success') {
$err .= 'IP:' . $domain . " \n\r 端口:" . $port . "国内icmp不通! \n\r";
}
if ($data1['tcp'] != 'success' && $data2['outside_tcp'] == 'success') {
$err .= 'IP:' . $domain . " \n\r 端口:" . $port . "国内tcp不通! \n\r";
}
// 都不通
if ($data1['icmp'] != 'success' && $data2['outside_icmp'] != 'success') {
$err .= 'IP:' . $domain . " \n\r 端口:" . $port . "国内外icmp不通! \n\r";
}
if ($data1['tcp'] != 'success' && $data2['outside_tcp'] != 'success') {
$err .= 'IP:' . $domain . " \n\r 端口:" . $port . "国内外tcp不通! \n\r";
}
}
header('content-type:application/json;charset=utf-8');
if (!empty($err)) {
$msg = curls('https://sc.ftqq.com/' . $skey . '.send?text=' . urlencode('主人,你的小鸡鸡被x了') . '&desp=' . urlencode($err));
$msg = json_decode($msg, true);
if ($msg['errno'] == 0) {
echo json_encode(['code' => 1, 'msg' => '通知成功!'], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
} else {
echo json_encode(['code' => 1, 'msg' => '通知失败!'], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
} else {
echo json_encode(['code' => 0, 'msg' => '小鸡安全'], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}

function curls($url, $post = '') {
$header[] = 'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_REFERER, 'https://www.toolsdaquan.com/ipcheck/');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
if (!empty($post)) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}

CGI运行Cli运行都可以(php 名称.php)
推荐Cli运行模式哦~

用宝塔的定时任务也就是crontab定时运行一下.就OK了.建议一小时运行一次就好了

赞(0)
未经允许不得转载:咸鱼博客 » 自动检查是否被Q脚本.发送消息到微信通知

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址