function is_online_for_inventory($ip)
{
    if (ifPingable($ip, $timeout = 1) != false) {
        # code...
        return "Online";
    } else {
        return "Offline";
    }
}
function getAllOnlineDevice($ipPool)
{
    $ipOnline = array();
    for ($i = 0; $i < sizeof($ipPool); $i++) {
        # code...
        if (ifPingable($ipPool[$i]) != false) {
            $ipOnline[] = $ipPool[$i];
            # code...
        }
    }
    return $ipOnline;
}
$ip[2] = $_POST["ip3"];
$comm[2] = $_POST["lb3"];
$mac[2] = $_POST["mac3"];
$sn[2] = $_POST["sn3"];
$lati[2] = $_POST["lati3"];
$long[2] = $_POST["long3"];
for ($i = 0; $i < 3; $i++) {
    # code...
    if ($ip[$i] != "" && $comm[$i] != "") {
        # code...
        if (ifPingable($ip[$i]) != false) {
            # code...
            echo $ip[$i] . " : " . $comm[$i];
            addDevice($ip[$i], $comm[$i], $mac[$i], $sn[$i], $lati[$i], $long[$i]);
        }
        if (ifPingable($ip[$i]) == false) {
            # code...
            echo $ip[$i] . " is not reachable!<br>";
        }
    }
}
echo "<br>";
echo "<br>";
echo "System needs to take a while for synchorizaiton.";
echo "<br>";
echo "<br>";
echo "<button onclick=closeWin()>Close</button>";
echo "<script>\nfunction closeWin() {\n\twindow.close();\n}\n</script>";
// the helper function that double chekcs the device is really reachable
function ifPingable($host, $timeout = 1)
{
        daemon_snmpScanIntoDb_1550($device_1550[$i]);
        // should be problem-free if having multiple 1550
    }
}
// elink: get snmp value and put it into database
// for ($i=0; $i < sizeof($device_elink); $i++) {
// 	# code...
// 	if (ifPingable($device_elink[$i]) != false) {
// 		# code...
// 		daemon_snmpScanIntoDb_elink($device_elink[$i]);   // should be problem-free if having multiple 1550
// 	}
// }
// egfa: get snmp value and put it into database
for ($i = 0; $i < sizeof($device_egfa); $i++) {
    # code...
    if (ifPingable($device_egfa[$i]) != false) {
        # code...
        daemon_snmpScanIntoDb_egfa($device_egfa[$i]);
        // should be problem-free if having multiple 1550
    }
}
// compare with threshold value; use the global timestamp to distinguish the online device
alarmCompare_1550($timestamp);
alarmCompare_egfa($timestamp);
// ---------------------------------------  for elink----------------------------------
//alarmCompare_elink($timestamp);
// ---------------------------------------  for elink----------------------------------
// use timestamp as the key to check if there is any new alarm record inserted. If yes, take action!
checkAlarmUpdatedIfYesTakeAction($timestamp);
//
// the helper function that double chekcs the device is really reachable
예제 #5
0
<?php

echo ifPingable("8.8.8.8");
echo "<br>";
$ip = "69.70.200.246";
$comm = "public";
$oid = ".1.3.6.1.2.1.1.1.0";
echo snmpget_generic($ip, $comm, $oid);
function ifPingable($host, $timeout = 3)
{
    /* ICMP ping packet with a pre-calculated checksum */
    $package = "}KPingHost";
    $socket = socket_create(AF_INET, SOCK_RAW, 1);
    socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));
    socket_connect($socket, $host, null);
    $ts = microtime(true);
    socket_send($socket, $package, strLen($package), 0);
    if (socket_read($socket, 255)) {
        $result = microtime(true) - $ts;
    } else {
        $result = false;
    }
    socket_close($socket);
    return $result;
}
function snmpget_generic($ip, $comm, $oid)
{
    $command = "C:\\usr\\bin\\snmpget -Ov -v 1 -c " . $comm . " " . $ip . " " . $oid . " 2>&1";
    $result = shell_exec($command);
    $result = ext($result);
    $result = removeQuotation($result);