强化Ping功能

- 添加Ping Api;
- Ping 支持多IP;
This commit is contained in:
兔姬桑
2022-06-15 22:05:24 +08:00
parent a06148ea12
commit 401b977ec7
2 changed files with 64 additions and 18 deletions

View File

@@ -15,13 +15,19 @@ class NetworkDetection
*/
public function ping(string $ip)
{
$round = 0;
$round = 1;
// 依次尝试接口
while (true) {
switch ($round) {
case 0:
$ret = $this->oiowebPing($ip);
break;
case 1:
$ret = $this->xiaoapiPing($ip);
break;
case 2:
$ret = $this->yum6Ping($ip);
break;
default:
return false;
}
@@ -59,6 +65,41 @@ class NetworkDetection
return false;
}
private function xiaoapiPing(string $ip)
{ // 来源 https://xiaoapi.cn/?action=doc&id=3
$msg = null;
$url = "https://xiaoapi.cn/API/sping.php?url={$ip}";
$response = Http::timeout(20)->get($url);
// 发送成功
if ($response->ok()) {
return $response->body();
}
Log::warning('【PING】检测'.$ip.'时xiaoapi.cn无结果');
// 发送错误
return false;
}
private function yum6Ping(string $ip)
{ // 来源 https://api.yum6.cn/ping.php?host=api.yum6.cn
$url = "https://api.yum6.cn/ping.php?host={$ip}";
$response = Http::timeout(20)->get($url);
// 发送成功
if ($response->ok()) {
$msg = $response->json();
if ($msg && $msg['state'] === '1000') {
return "<h4>{$msg['ip']}</h4>线路【{$msg['node']}】<br> 最小值:{$msg['ping_time_min']}<br> 平均值:{$msg['ping_time_avg']}<br> 最大值:{$msg['ping_time_max']}";
}
}
Log::warning('【PING】检测'.$ip.'时api.yum6.cn无结果');
// 发送错误
return false;
}
/**
* 通过众多API进行节点阻断检测.
*