gilesw
Joined: 13 Sep 2003 Posts: 9
|
Posted: Thu Apr 10, 2008 5:36 am Post subject: icmp ping that doesn't require root |
|
|
| Code: | function ping_icmp() {
/* ping me */
if ($this->host["hostname"]) {
/* initialize variables */
$this->ping_status = "down";
$this->ping_response = "ICMP Ping timed out";
/* establish timeout variables */
$to_sec = floor($this->timeout/1000);
$to_usec = ($this->timeout%1000)*1000;
/* clean up hostname if specifying snmp_transport */
$this->host["hostname"] = str_replace("TCP:", "", $this->host["hostname"]);
$this->host["hostname"] = str_replace("UDP:", "", $this->host["hostname"]);
/* determine the host's ip address */
$host_ip = gethostbyname($this->host["hostname"]);
$this->ping_response = "$host_ip";
$ping_output = system("ping $host_ip -c 1", $retval);
preg_match('/rtt/', $ping_output, $ping_worked);
if ($ping_worked){
$this->ping_status = 1000;
$this->ping_response = "Host is alive";
return true;
}else {
$this->response = "Host is dead";
return false;
}
}
}
|
I'd like to use cactid but it won't run ICMP unless it is running as root.
But this code certainly gets round any issues you may have with getting ICMP to work with cmd.php |
|