Пример #1
0
 /**
  * SocketPingWrapper::Ping()
  * 
  * @return boolean true when ping is executed false when ping failed to execute.
  */
 function Ping($try = array('http', 'ftp', 'telnet', 'mail'))
 {
     if (empty($try)) {
         $try = array('http', 'ftp', 'telnet', 'mail');
     } else {
         if (!is_array($try)) {
             $try = array($try);
         }
     }
     if (empty($this->mInput)) {
         if (false !== $this->mDebug) {
             echo "Error: no ping target specified.";
         }
         return false;
     }
     if (!is_array($this->mInput)) {
         $this->mInput = array($this->mInput);
     }
     foreach ($this->mInput as $key => $host) {
         $this->mInfo = array();
         $up = false;
         foreach ($try as $service) {
             $tping = new TcpPing($host, $service);
             if ($result = $tping->Ping()) {
                 $up = true;
                 $this->mInfo[] = "service={$service} time=" . $tping->GetTime();
                 break;
             } else {
                 /**
                  * If current error message is different from the last one, take it.
                  */
                 if (!sizeof($this->mInfo) || $tping->GetErrorMessage() != $this->mInfo[sizeof($this->mInfo) - 1]) {
                     $this->mInfo[] = $tping->GetErrorMessage();
                 }
             }
         }
         $this->mOutput[] = "{$host} [" . $tping->GetTargetAddress() . "] is  " . ($up ? 'Alive.' : 'Down!!') . ' ' . implode(" ", $this->mInfo);
     }
     return true;
 }
Пример #2
0
<?php

header('refresh: 10; url= http://freenet.surething.biz/phpBB2/viewforum.php?f=2');
#header( 'refresh: 20; url= http://google.com' );
require_once "tcp_ping.class.php";
print "<U><B><BIG>Network Conectivity Test results</BIG></B></U><BR><BR>";
$host = "router";
$pinger = new TcpPing("{$host}", "http", 2);
$good = $pinger->Ping();
if ($good == 1) {
    print "ping of host {$host} looks good <BR>";
} else {
    print "FreeNET router ping failure! This may be a FreeNet problem. please inform scotty of failure  <BR>";
    print " phone 086-827-0277 if other Internet connections fail.<BR>";
    exit;
}
#$host="72.14.207.99";
$host = "google.com";
$pinger->mTargetHost = trim($host);
$good = $pinger->ping();
if ($good == 1) {
    print "<BR>Ping of host google.com looks good <BR>";
} else {
    print "ping of host google.com failed. This could be a TOT problem please try again later <BR>  If problem continues for more that 24 hours contact Scotty at PH# 086-827-0277 <BR>";
}
// phpinfo(); exit();
// header( 'refresh: .1; url= http://google.com' );
//   header( 'refresh: 3; url= http://surething.biz' );
Пример #3
0
<?php

require_once "tcp_ping.class.php";
$host = "router";
$pinger = new TcpPing("{$host}", "http", 2);
$good = $pinger->Ping();
if ($good != 1) {
    print "bad_route_ping";
    exit;
}
#$host="google.com";
$host = "8.8.8.8";
$pinger2 = new TcpPing("{$host}", "domain", 2);
$good = $pinger2->ping();
if ($good == 1) {
    print "imalive";
} else {
    print "bad_google_ping";
}