From 850f52e128dbbcab8c208e51941cce9bf4c905d0 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Thu, 25 Jun 2020 15:54:56 +0200 Subject: [PATCH] Create internetRoute.php --- includes/internetRoute.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 includes/internetRoute.php diff --git a/includes/internetRoute.php b/includes/internetRoute.php new file mode 100644 index 00000000..711d7fff --- /dev/null +++ b/includes/internetRoute.php @@ -0,0 +1,33 @@ + $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) + 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 + exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_IP.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\;$ + if (empty($okip)) $okip[0]="failed"; + $rInfo[$i]["access-ip"] = $okip[0]; + exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_DNS.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\$ + if (empty($okdns)) $okdns[0]="failed"; + $rInfo[$i]["access-dns"] = $okdns[0]; + } + } + } else { + $data = array("error"=>"No route to the internet found"); + } + $rInfo_json = json_encode($rInfo); +?>