2020-06-25 15:54:56 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
define("ACCESS_CHECK_IP","1.1.1.1");
|
|
|
|
define("ACCESS_CHECK_DNS","one.one.one.one");
|
|
|
|
|
|
|
|
$rInfo=array();
|
|
|
|
// get all default routes
|
2020-06-25 16:55:25 +02:00
|
|
|
exec('ip route list | sed -rn "s/default via (([0-9]{1,3}\.){3}[0-9]{1,3}).*dev (\w*).*src (([0-9]{1,3}\.){3}[0-9]{1,3}).*/\3 \4 \1/p"',$routes);
|
2020-06-25 15:54:56 +02:00
|
|
|
if ( !empty($routes) ) {
|
|
|
|
foreach ($routes as $i => $route) {
|
|
|
|
$prop=explode(' ',$route);
|
|
|
|
$rInfo[$i]["interface"]=$prop[0];
|
|
|
|
$rInfo[$i]["ip-address"]=$prop[1];
|
|
|
|
$rInfo[$i]["gateway"]=$prop[2];
|
|
|
|
// resolve the name of the gateway (if possible)
|
2020-06-25 17:18:23 +02:00
|
|
|
unset($host);
|
2020-06-25 15:54:56 +02:00
|
|
|
exec('host '.$prop[2].' | sed -rn "s/.*domain name pointer (.*)\./\1/p" | head -n 1',$host);
|
|
|
|
if (empty($host)) $host[0]="*";
|
|
|
|
$rInfo[$i]["gw-name"] = $host[0];
|
|
|
|
if (isset($checkAccess) && $checkAccess) {
|
|
|
|
// check internet connectivity w/ and w/o DNS resolution
|
2020-06-25 17:18:23 +02:00
|
|
|
unset($okip);
|
2020-06-25 16:55:25 +02:00
|
|
|
exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_IP.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\;/p"',$okip);
|
2020-06-25 15:54:56 +02:00
|
|
|
if (empty($okip)) $okip[0]="failed";
|
|
|
|
$rInfo[$i]["access-ip"] = $okip[0];
|
2020-06-25 17:18:23 +02:00
|
|
|
unset($okdns);
|
2020-06-25 16:55:25 +02:00
|
|
|
exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_DNS.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\;/p"',$okdns);
|
2020-06-25 15:54:56 +02:00
|
|
|
if (empty($okdns)) $okdns[0]="failed";
|
|
|
|
$rInfo[$i]["access-dns"] = $okdns[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2020-06-25 16:55:25 +02:00
|
|
|
$rInfo = array("error"=>"No route to the internet found");
|
2020-06-25 15:54:56 +02:00
|
|
|
}
|
|
|
|
$rInfo_json = json_encode($rInfo);
|
|
|
|
?>
|