Esempio n. 1
0
 function getInterfaces()
 {
     $output = NetworkBo::sendCommand("ifconfig");
     $lines = preg_split("/\n/", $output);
     $currentInterface = array();
     $interfaces = array();
     foreach ($lines as $index => $line) {
         if (!$line) {
             if (isset($currentInterface["name"])) {
                 $interfaces[$currentInterface["name"]] = $currentInterface;
             }
             $currentInterface = array();
         } else {
             // 				echo $line . "<br>";
             // 				print_r($currentInterface);
             // 				echo "<br>";
             $re = "/^([a-z0-9\\.\\-]+)\\s*Link encap:([A-Za-z0-9]+)\\s*(HWaddr)?\\s*([a-z0-9:\\-]*)/";
             preg_match_all($re, $line, $matches);
             if ($matches[0]) {
                 $currentInterface["name"] = $matches[1][0];
                 if ($matches[4]) {
                     $currentInterface["mac"] = $matches[4][0];
                 }
             }
             $re = "/addr:([0-9\\.]*)/";
             preg_match_all($re, $line, $matches);
             if ($matches[1] && $matches[1][0]) {
                 $currentInterface["ip_v4"] = $matches[1][0];
             }
             $re = "/6 addr:\\s*([a-z0-9\\:\\/\\-%]*) Scope:(\\w*)/";
             preg_match_all($re, $line, $matches);
             if ($matches[1] && $matches[1][0]) {
                 // 					print_r($matches);
                 // 					echo "<br>";
                 $currentInterface["ip_v6_" . strtolower($matches[2][0])] = $matches[1][0];
             }
         }
     }
     // 		print_r($interfaces);
     // 		echo "<br>";
     return $interfaces;
 }
Esempio n. 2
0
 function getInterfaces()
 {
     $output = NetworkBo::sendCommand("ifconfig");
     $lines = preg_split("/\n/", $output);
     $currentInterface = array();
     $interfaces = array();
     foreach ($lines as $index => $line) {
         if (!$line) {
             if (isset($currentInterface["name"])) {
                 $interfaces[$currentInterface["name"]] = $currentInterface;
             }
             $currentInterface = array();
         } else {
             $re = "/^([a-z0-9\\.]+)\\s*Link encap:([A-Za-z0-9]+)\\s*(HWaddr)?\\s*([a-z0-9:\\-]*)/";
             preg_match_all($re, $line, $matches);
             if ($matches[0]) {
                 $currentInterface["name"] = $matches[1][0];
                 if ($matches[4]) {
                     $currentInterface["mac"] = $matches[4][0];
                 }
             }
             $re = "/inet addr:([0-9\\.]*)/";
             preg_match_all($re, $line, $matches);
             if ($matches[1]) {
                 $currentInterface["ip_v4"] = $matches[1][0];
             }
             $re = "/addr: ([a-f0-9\\:\\/]*)/";
             preg_match_all($re, $line, $matches);
             if ($matches[1]) {
                 $currentInterface["ip_v6"] = $matches[1][0];
             }
         }
     }
     return $interfaces;
 }