-
Notifications
You must be signed in to change notification settings - Fork 0
/
cjdnsPING.php
45 lines (35 loc) · 1.2 KB
/
cjdnsPING.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
//Read existing nodes
$tmp=file_get_contents ("/var/www/html/ping.json");
$pingNodes=json_decode($tmp, true);
// Initiate curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,"https://raw.githubusercontent.com/tomeshnet/node-list/master/nodeList.json");
$result=curl_exec($ch);
curl_close($ch);
// Will dump a beauty json :3
foreach (json_decode($result, true) as $node) {
if (isset($node['IPV6Address'])) {
$pingNodes[$node['IPV6Address']]=pingAddress($node['IPV6Address']);
}
}
file_put_contents ("/var/www/html/ping.json", json_encode($pingNodes));
function pingAddress($ip) {
$pingresult = exec("/bin/ping6 -c 5 $ip", $outcome, $status);
if (0 == $status) {
$val=explode(" ",$pingresult);
$stats=explode("/",$val[3]);
$pingData['status']='ok';
$pingData['pingMin']=$stats[0];
$pingData['pingAvg']=$stats[1];
$pingData['pingMax']=$stats[2];
} else {
$pingData['status']='dead';
$pingData['pingMin']=-1;
$pingData['pingAvg']=-1;
$pingData['pingMax']=-1;
}
$pingData['lastPing']=date("Y-m-j H:i:s");
return $pingData;
}