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);
exec('ip route list | sed -rn "s/default dev (\w*) scope link/\1/p"',$devs);
if(!empty($devs)){
foreach($devsas$dev)
exec('ip route list | sed -rn "s/(([0-9]{1,3}\.){3}[0-9]{1,3}).*dev.*("'.$dev.'").*scope link src (([0-9]{1,3}\.){3}[0-9]{1,3}).*/\3 \4 \1/p"',$routes);
}
if(!empty($routes)){
foreach($routesas$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)
unset($host);
exec('host '.$prop[2].' | sed -rn "s/.*domain name pointer (.*)\./\1/p" | head -n 1',$host);
$rInfo[$i]["gw-name"]=empty($host)?"*":$host[0];
if(isset($checkAccess)&&$checkAccess){
// check internet connectivity w/ and w/o DNS resolution