admin.php 978 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace Statistics\Modules;
  3. function admin()
  4. {
  5. $act = isset($_GET['act'])? $_GET['act'] : 'home';
  6. switch($act)
  7. {
  8. case 'detect_server':
  9. $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  10. socket_set_option($socket, SOL_SOCKET, SO_BROADCAST, 1);
  11. $buffer = json_encode(array('cmd'=>'REPORT_IP'))."\n";
  12. socket_sendto($socket, $buffer, strlen($buffer), 0, '255.255.255.255', \Statistics\Web\Config::$ProviderPort);
  13. $time_start = microtime(true);
  14. $time_out = 2;
  15. $ip_list = array();
  16. while(microtime(true) - $time_start < $time_out)
  17. {
  18. $buf = $host = $port = '';
  19. if(socket_recvfrom($socket, $buf, 65535, 0, $host, $port))
  20. {
  21. $ip_list[$host] = $host;
  22. echo $buf;
  23. var_export($ip_list);
  24. }
  25. }
  26. break;
  27. }
  28. }