Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. <?php
  2. function ping($ip = "127.0.0.1")
  3. {
  4. if (empty($ip)) {
  5. $ip = $_SERVER['REMOTE_ADDR'];
  6. }
  7. if (getenv("OS") == "Windows_NT") {
  8. $exec = exec("ping " . $ip);
  9. $ping = explode(",", $exec);
  10. return $ping;
  11. } else {
  12. $exec = exec("ping -c 3 -s 64 -t 64 " . $ip);
  13. $array = explode("/", end(explode("=", $exec)));
  14. if (strpos($array[0], "packets") !== false) {
  15. $array[0] = "error";
  16. $array[1] = "error";
  17. $array[2] = "error";
  18. $array[3] = "error";
  19. }
  20. return $array;
  21. }
  22. }
  23. ?>
  24. <h1>check ping data</h1>
  25. <table border="1">
  26. <tr>
  27. <th>Site</th>
  28. <th>Min</th>
  29. <th>Avg</th>
  30. <th>Max</th>
  31. <th>Persentase</th>
  32. <th>Color</th>
  33. </tr>
  34.  
  35. <?php
  36. $web = array(
  37. 'www.google.com',
  38. 'www.facebook.com',
  39. 'www.detik.com',
  40. 'www.datautama.net',
  41. 'sim.ubhara.ac.id'
  42. );
  43.  
  44. foreach ($web as $value) {
  45. $result = ping($value);
  46. $arr = explode("packets", $result[1], 2);
  47. ?>
  48. <tr>
  49. <td><?php echo $value; ?></td>
  50. <td><?php echo $result[0]; ?></td>
  51. <td><?php echo $result[1]; ?></td>
  52. <td><?php echo $result[2]; ?></td>
  53. <td>0%</td>
  54. <?php
  55. if ($result[0] != "error") {
  56. echo "<td bgcolor=\"#00FF00\"></td>";
  57. } else {
  58. echo "<td bgcolor=\"#FF0000\"></td>";
  59. }
  60. ?>
  61. </tr>
  62. <?php
  63. }
  64.  
  65. ?>
  66.  
  67.  
  68. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement