ping.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. create_home_selector("util","",$server_homes);
  3. if( isset( $_GET['home_id']) )
  4. {
  5. if ( isset($_SERVER["REMOTE_ADDR"]) )
  6. {
  7. $client_ip = $_SERVER["REMOTE_ADDR"];
  8. }
  9. elseif ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) )
  10. {
  11. $client_ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
  12. }
  13. elseif( isset($_SERVER["HTTP_CLIENT_IP"]) )
  14. {
  15. $client_ip = $_SERVER["HTTP_CLIENT_IP"];
  16. }
  17. ?>
  18. <form method="post" action="">
  19. <input name="ping" type="submit" value="PING SERVER" />
  20. </form>
  21. <?php
  22. if(isset($_POST['ping']))
  23. {
  24. $ip = $client_ip;
  25. if(!empty($ip))
  26. {
  27. $ping = "";
  28. $home_info = $db->getGameHomeWithoutMods($server_home['home_id']);
  29. require_once('includes/lib_remote.php');
  30. $remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'],$home_info['timeout']);
  31. $os = $remote->what_os();
  32. if(preg_match("/CYGWIN/",$os))
  33. {
  34. $exec = $remote->exec("ping -n 1 -l 64 ".$ip);
  35. $ping = end(explode(" ", $exec ));
  36. }
  37. else
  38. {
  39. $exec = $remote->exec("ping -c 1 -s 64 -t 64 ".$ip);
  40. $array = explode("/", end(explode("=", $exec )) );
  41. $ping = ceil($array[1]) . 'ms';
  42. }
  43. }
  44. ?><p style="color:blue;text-align:center;">Server IP: <?php
  45. echo $server_home['agent_ip'];
  46. echo " --> ".$ping." --> ";
  47. ?>Your IP: <?php
  48. echo $ip;
  49. ?></p><?php
  50. }
  51. }
  52. ?>