Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function ping($ip = "127.0.0.1")
- {
- if (empty($ip)) {
- $ip = $_SERVER['REMOTE_ADDR'];
- }
- if (getenv("OS") == "Windows_NT") {
- $exec = exec("ping " . $ip);
- $ping = explode(",", $exec);
- return $ping;
- } else {
- $exec = exec("ping -c 3 -s 64 -t 64 " . $ip);
- $array = explode("/", end(explode("=", $exec)));
- if (strpos($array[0], "packets") !== false) {
- $array[0] = "error";
- $array[1] = "error";
- $array[2] = "error";
- $array[3] = "error";
- }
- return $array;
- }
- }
- ?>
- <h1>check ping data</h1>
- <table border="1">
- <tr>
- <th>Site</th>
- <th>Min</th>
- <th>Avg</th>
- <th>Max</th>
- <th>Persentase</th>
- <th>Color</th>
- </tr>
- <?php
- $web = array(
- 'www.google.com',
- 'www.facebook.com',
- 'www.detik.com',
- 'www.datautama.net',
- 'sim.ubhara.ac.id'
- );
- foreach ($web as $value) {
- $result = ping($value);
- $arr = explode("packets", $result[1], 2);
- ?>
- <tr>
- <td><?php echo $value; ?></td>
- <td><?php echo $result[0]; ?></td>
- <td><?php echo $result[1]; ?></td>
- <td><?php echo $result[2]; ?></td>
- <td>0%</td>
- <?php
- if ($result[0] != "error") {
- echo "<td bgcolor=\"#00FF00\"></td>";
- } else {
- echo "<td bgcolor=\"#FF0000\"></td>";
- }
- ?>
- </tr>
- <?php
- }
- ?>
- </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement