Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function ping($ip){
- error_reporting(0);
- if (!isset($ip) || $ip == null || $ip == "") { $status = "You didn't enter an IP/hostname."; } else {
- if ($ip == "127.0.0.1" || $ip == "localhost")
- { $status = "Be serious. I'm not going to ping myself, am I? Use me constructively, or get the fuck out."; }
- else {
- $sttime = microtime(true);
- $connect = fsockopen ($ip, 80, $errno, $errstr, 10);
- $sptime = microtime(true);
- $status = 0;
- if (!$connect) { $status = -1; } // IP/host is not available
- else {
- fclose($connect);
- $status = ($sptime - $sttime) * 1000;
- $status = floor($status);
- }}}
- if (is_string($status)) { $result = "$status"; }
- elseif ($status != -1) { $result = "$ip is active, with ping of " . $status . " ms!"; }
- else { $result = "$ip was unreachable!"; }
- return $result;
- }
- // USAGE
- // echo ping(*the IP to ping*);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement