select_db('share'); echo("\n====================== Kontrola online pocitacu ============================\n\n"); //while (true) { echo('Nacitam strom sdileni...'); $Output = array(); exec('smbtree -N -S',$Output,$Return); //echo($Return."\n"); echo("OK\n\nSeznam online pocitacu:\n"); array_shift($Output); $Online = array(); // Seznam online pocitacu foreach ($Output as $Radek) { if (ord($Radek[0])!=9) continue; $Host = explode(' ',substr($Radek,3)); $Host = $Host[0]; // echo($Host); $Section = 0; // Zjisti IP a MAC adresu if ($Host=='CENTRALA') { $MAC = '00:E0:4C:20:64:22'; $IP = '192.168.0.1'; $Section = 0; } else if ($Host=='CENTRALA2') { $MAC = '00:E0:4C:20:64:22'; $IP = '192.168.0.11'; $Section = 0; } else { $Output = array(); //echo('arping -c 1 '.$Host); exec('arping -c 1 '.$Host,$Output); if (count($Output)!=4) { $Output = array(); exec('arping -I wlan0 -c 1 '.$Host,$Output); if (count($Output)!=4) { $Output = array(); exec('arping -I wlan1 -c 1 '.$Host,$Output); if (count($Output)!=4) { $Output = array(); exec('arping -I wlan2 -c 1 '.$Host,$Output); if (count($Output)!=4) { $Output = array(); exec('arping -I eth2 -c 1 '.$Host,$Output); if (count($Output)!=4) continue; else $Section = 4; } else $Section = 3; } else $Section = 2; } else $Section = 1; } else $Section = 0; $Output = explode(' ',$Output[1]); $MAC = substr($Output[4],1,-1); $IP = $Output[3]; } echo($Host.": IP:".$IP." MAC:".$MAC." Sekce:".$Section."\n"); array_push($Online, array('host' => $Host, 'IP' => $IP, 'MAC' => $MAC, 'section' => $Section)); } // Deaktivuj predchozi online pocitace $Database->update('hosts', 1, array('online' => 0)); // Aktivuj online pocitace foreach ($Online as $Item) { $DbResult = $Database->query("SELECT * FROM hosts WHERE name='".$Item['host']."'"); if ($DbResult->num_rows > 0) { $Database->update('hosts',"name='".$Item['host']."'",array( 'IP' => $Item['IP'], 'MAC' => $Item['MAC'], 'online' => 1, 'lastdate' => 'NOW()', 'section' => $Section)); } else $Database->insert('hosts',array('name' => $Item['host'], 'IP' => $Item['IP'], 'MAC' => $Item['MAC'], 'online' => 1,'date' => 'NOW()','lastdate' => 'NOW()', 'section' => $Section)); } echo("\nSeznam offline pocitacu:\n"); $DbResult = $Database->query("SELECT * FROM hosts WHERE online=0"); while ($Row = $DbResult->fetch_array()) { echo($Row['name'].", "); } // sleep(1000); //echo("\nCekam minutu..."); //sleep(60); //echo("OK\n\n"); } echo("\n\nKontrola dokoncena\n\n");