Пример #1
0
 /**
  * @return bool|mixed
  */
 private function _getWifiNetworks()
 {
     $wlans = wifi_data::where('key', '=', 'networks')->first();
     if ($wlans != null) {
         $wlans = json_decode($wlans->value);
         return $wlans;
     } else {
         return false;
     }
 }
Пример #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $output = array();
     //Inf loop of scanning//
     $iw = shell_exec('iwlist wlan0 scan');
     if (strlen($iw) < 30) {
         echo "-";
         exit(1);
     }
     ///We should have the output ...//
     $iw = explode("\n", $iw);
     $x = -1;
     foreach ($iw as $line) {
         //this should be the first line//
         if (stristr($line, "Cell ")) {
             if ($x >= 0) {
                 //We need to save it//
                 $FOUND_SAVED = -1;
                 foreach ($output as $saved) {
                     if ($saved->name == $iwo->name) {
                         $FOUND_SAVED = 1;
                     }
                 }
                 if ($FOUND_SAVED == -1) {
                     $output[] = $iwo;
                 }
             }
             $x++;
             $iwo = new ifw();
         }
         //WPA2
         if (stristr($line, "IE: IEEE")) {
             $sec = explode("/", $line);
             $sec = explode(" ", $sec[1]);
             $sec = $sec[0];
             $iwo->sec = $sec;
         }
         //IE: WPA
         if (stristr($line, "IE: WPA")) {
             $iwo->sec = "WPA";
         }
         if (stristr($line, "Quality=")) {
             $qual = explode("=", $line);
             $qual = explode('/', $qual[1]);
             $qual = round($qual[0] / 70 * 100);
             // in percent//
             $iwo->signal = $qual;
         }
         if (stristr($line, "ESSID:")) {
             $name = explode(":", $line);
             $name = str_replace('"', "", $name[1]);
             $iwo->name = $name;
         }
         if (stristr($line, "Encryption key")) {
             if (stristr($line, ":on")) {
                 $iwo->secure = 1;
             } else {
                 $iwo->secure = -1;
             }
         }
     }
     $output[] = $iwo;
     $json = json_encode($output);
     if (strlen($json) == 0) {
         exit(1);
     }
     $c = wifi_data::where('key', '=', 'networks')->get()->count();
     if ($c == 0) {
         $wdata = new wifi_data();
         $wdata->key = "networks";
     } else {
         $wdata = wifi_data::where('key', '=', 'networks')->first();
     }
     //dd($wdata);
     $wdata->value = $json;
     $wdata->save();
     //print_r($output);
     echo "+";
 }