Advertisement
ZER0X304

Untitled

Apr 22nd, 2011
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. <?php
  2.  
  3. function ping($ip){
  4.  
  5.     error_reporting(0);
  6.  
  7.     if (!isset($ip) || $ip == null || $ip == "") { $status = "You didn't enter an IP/hostname."; } else {
  8.  
  9.     if ($ip == "127.0.0.1" || $ip == "localhost")
  10.     { $status = "Be serious. I'm not going to ping myself, am I? Use me constructively, or get the fuck out."; }
  11.     else {
  12.  
  13.     $sttime    = microtime(true);
  14.     $connect   = fsockopen ($ip, 80, $errno, $errstr, 10);
  15.     $sptime    = microtime(true);
  16.     $status    = 0;
  17.  
  18.     if (!$connect) { $status = -1; } // IP/host is not available
  19.     else {
  20.         fclose($connect);
  21.         $status = ($sptime - $sttime) * 1000;
  22.         $status = floor($status);
  23.     }}}
  24.    
  25.     if (is_string($status)) { $result = "$status"; }
  26.     elseif ($status != -1) { $result = "$ip is active, with ping of " . $status . " ms!"; }
  27.     else { $result = "$ip was unreachable!"; }
  28.    
  29.     return $result;
  30. }
  31.  
  32. // USAGE
  33. // echo ping(*the IP to ping*);
  34.  
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement