function ping($host) { $pingObj = Net_Ping::factory(); $response = $pingObj->ping($host); if (!isset($response->_transmitted)) { //we can't find the host name, assume it's off $response->_transmitted = 1; $response->_received = 0; } $result = array('transmitted' => $response->_transmitted, 'received' => $response->_received); return $result; }
function ServiceStatus() { //require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/classes/shared/ServerPing.class.php"); //$this->ServerPing = new ServerPing(); require "Net/Ping.php"; //Net_Ping::setArgs($this->ServerPing); $this->ServerPing = Net_Ping::factory(); /*$this->ServerPing = new Net_Ping(); $this->ServerPing->setArgs($this->NetPingArguments); $this->ServerPing->factory();*/ }
<td>History</td> </tr> </thead> <tbody> <?php $sql = "Select pkCabinetDetailsID, pkCabinetID, ServerLabel, IP, Client, pkClientID, SendEmail, SwitchPort, SwitchLabel, PDULabel, PDUPort, Password from tblCabinetDetails\n\tleft outer join tblClient on pkClientID = fkClientID\n\tleft outer join tblCabinet on pkCabinetID = fkCabinetID\n\t\twhere IP > ''\n\torder by pkCabinetID, SwitchPort, ServerLabel"; $sqld = "delete from tblPing\n\t\t\twhere \n\t\t\tdate_format(date_sub(concat(CURRENT_DATE(), ' ', CURRENT_TIME()), INTERVAL 24 hour),'%Y-%m-%d %h:%i:%s') \n\t\t\t>= \n\t\t\tdate_format(datetime,'%Y-%m-%d %h:%i:%s')\n\t\t\t"; $resd = $db->executeNonQuery($sqld); //execute the query $res = $db->executeQuery($sql); //execute the query $i = 0; $class = ' altrow'; while ($res != -1 && ($row = mysql_fetch_assoc($res))) { $ping = Net_Ping::factory(); if (PEAR::isError($ping)) { echo $ping->getMessage(); } else { $ping->setArgs(array('count' => 1)); $results = object_2_array($ping->ping($row['IP'])); $r = 0; while ($results['_received'] == 0 && $r < 5) { $results = object_2_array($ping->ping($row['IP'])); $r++; } } //print_r($results); $htmlx = "Login: "******", Password: "******"\n"; $sqlp = "Select * from tblCabinetDetails where fkCabinetID in (\n\tSelect fkCabinetID from tblCabinetDetails where IP = '" . $row['IP'] . "'\n\t) and fkClientID in (10,18)"; $resp = $db->executeQuery($sqlp);
/** * Ping selected address with PEAR ping package * * @access protected * @param ip $address * @return void */ protected function ping_address_method_pear($address) { # we need pear ping package require_once dirname(__FILE__) . '/../../functions/PEAR/Net/Ping.php'; $ping = Net_Ping::factory(); # check for errors if ($ping->pear->isError($ping)) { $this->throw_exception("Error: " . $ping->getMessage()); } else { //set count and timeout $ping->setArgs(array('count' => $this->icmp_timeout, 'timeout' => $this->icmp_timeout)); //execute $ping_response = $ping->ping($address); //check response for error if ($ping->pear->isError($ping_response)) { $result['code'] = 2; } else { //all good if ($ping_response->_transmitted == $ping_response->_received) { $result['code'] = 0; $this->rtt = "RTT: " . strstr($ping_response->_round_trip['avg'], ".", true); } elseif ($ping_response->_received == 0) { $result['code'] = 1; } else { $result['code'] = 3; } } } //return result for web or cmd exit($result['code']); }
/** * Ping host - PEAR */ function pingHostPear($ip, $count = "1", $timeout = 1, $exit = false) { require_once "PEAR/Net/Ping.php"; $ping = Net_Ping::factory(); if (PEAR::isError($ping)) { echo $ping->getMessage(); } else { $ping->setArgs(array('count' => $count, 'timeout' => 1)); $pRes = $ping->ping($ip); // check response if (PEAR::isError($pRes)) { $result['code'] = 2; $result['text'] = $pRes->message; $result['text'] = $pRes->getMessage(); } else { //all good if ($pRes->_transmitted == $pRes->_received) { $result['code'] = 0; $result['text'] = "RTT: " . $pRes->_round_trip['avg'] . " ms"; } elseif ($pRes->_received == 0) { $result['code'] = 1; $result['text'] = "Offline"; } else { $result['code'] = 3; $result['text'] = "Unknown error"; } } } //exit codes // 0 = online // 1 = offline // 2 = error // 3 = unknown error //return result for web or cmd if (!$exit) { return $result; } else { exit($result['code']); } }
function ping($ip) { include_once $_CONF[root_dir] . $_CONF[pear_dir] . "Net/Ping.php"; $pingdata = array(); $ping = Net_Ping::factory(); if (PEAR::isError($ping)) { echo $ping->getMessage(); } else { $ping->setArgs(array('count' => 2, 'size' => 32, 'deadline' => 1, 'timeout' => '4')); $ret = $ping->ping($ip); if (!$ret->getBytesTotal() > 0) { sleep(2); $ret = $ping->ping($ip); } $pingdata[alertType] = 'serverDown'; if (get_class($ret) == 'Net_Ping_Result') { if ($ret->getBytesTotal() > 0) { $pingdata[alertSymbol] = 'ok'; $pingdata[alertNote] = 'server up (ping passed)'; $pingdata[alertText] = implode("\n", $ret->getRawData()); $pingdata['Time'] = $ret->getAvg(); } else { $pingdata[alertSymbol] = 'error'; $pingdata[alertNote] = 'server down (ping failed)'; $pingdata[alertText] = implode("\n", $ret->getRawData()); $pingdata['Time'] = -100; } } else { if (get_class($ret) == 'PEAR_Error') { $pingdata[alertSymbol] = 'error'; $pingdata[alertNote] = $ret->getMessage(); $pingdata[alertText] = $ret->getMessage(); $pingdata['Time'] = -100; } } } return $pingdata; }