Example #1
2
 /**
  * Do snmpwalk
  *
  * @param unknown_type $rootOID
  * @return array Array of values
  */
 public function GetTree($rootOID = null)
 {
     try {
         $retval = @snmpwalk($this->Connection, $this->Community, $rootOID, $this->Timeout);
     } catch (Exception $e) {
         $this->RaiseWarning("Cannot walk through {$this->Connection}/{$this->Community}/{$rootOID}" . $e->__toString());
     }
     return $retval;
 }
         
        <tr>
        <td colspan = "1">
        <a href='index.php'>HOME</td> 
            	    
            	    
            	   
            	    	
        <td style="height:600px;width:2000px;vertical-align:top;">
        <center><br>
        <form action = "a3n3.php" method = "POST">  
          <?php 
$IP = $_POST["IP"];
$PORT = $_POST["PORT"];
$COMMUNITY = $_POST["COMMUNITY"];
$int = snmpwalk("{$IP}:{$PORT}", "{$COMMUNITY}", '1.3.6.1.2.1.2.2.1.1', 100000, 5);
$device = "{$COMMUNITY}-{$IP}-{$PORT}";
if ($int) {
    echo "The interfaces of the selected device {$COMMUNITY}, {$IP} and {$PORT} are:";
    echo "<br><table border = '1'>";
    foreach ($int as $x) {
        $i = explode(' ', $x);
        echo "<tr><td><input type = 'checkbox' name ='list[]' value = {$i['1']},{$device}> {$i['1']}</td></tr>";
    }
} else {
    echo "<br>The device is down. Cannot add<br>";
}
?>
     
       </table><br>
Example #3
0
function SNMPwalk_Render(&$parser, $snmphost = '127.0.0.1', $com = 'public', $snmpoid = 'SNMPv2-SMI::mib-2.1.6.0', $prefix, $suffix)
{
    $arr = snmpwalk($snmphost, $com, $snmpoid, 50000);
    $result = '';
    foreach ($arr as $value) {
        if (isset($prefix)) {
            $result .= "{$prefix} ";
        }
        $result .= clean_Result($value) . " ";
        if (isset($suffix)) {
            $result .= $suffix;
        }
    }
    return $result;
}
function snmp_walk($snmp_host, $snmp_community, $snmp_oid, $snmp_version)
{
    if (extension_loaded("snmp")) {
        if ($snmp_version == "1") {
            if ($snmp_return = @snmpwalk($snmp_host, $snmp_community, $snmp_oid)) {
                return $snmp_return;
            } else {
                show_help("SNMP");
            }
        } else {
            if ($snmp_version == "2c" || $snmp_version == "2") {
                if ($snmp_return = @snmp2_walk($snmp_host, $snmp_community, $snmp_oid)) {
                    return $snmp_return;
                } else {
                    show_help("SNMP");
                }
            } else {
                show_help("SNMP");
            }
        }
    } else {
        show_help("SNMP_MODULE");
    }
}
}
if (empty($_GET['i'])) {
    $i = 'empty';
} else {
    $i = $_GET['i'];
}
$result = mysql_query("SELECT * FROM hosts WHERE host like '%{$q}%'");
while ($row = mysql_fetch_array($result)) {
    $ip = $row['ip'];
    $s = $row['ifdescr'];
}
$result1 = mysql_query("SELECT * FROM hosts WHERE host like'%{$q}%' and idinterface ='{$i}'");
$community = 'public';
$outoctets = snmpwalk("{$ip}", "{$community}", "1.3.6.1.2.1.2.2.1.16");
$inoctets = snmpwalk("{$ip}", "{$community}", "1.3.6.1.2.1.2.2.1.10");
$interf = snmpwalk("{$ip}", "{$community}", "1.3.6.1.2.1.2.2.1.8");
while ($row1 = mysql_fetch_array($result1)) {
    //$interf=$row1['ifoperstatus'];
    //$inoctets=$row1['inoctets'];
    //$outoctets=$row1['outoctets'];
    $ifdescr = $row1['ifdescr'];
}
$inoctets1 = substr($inoctets[$i], 10, 17);
$outoctets1 = substr($outoctets[$i], 10, 17);
$ifdescr1 = substr($ifdescr, 7, 17);
$interf1 = substr($interf[$i], 8, -3);
$inmbps = (int) ($inoctets1 / 1048576) * 8;
$outmbps = (int) ($outoctets1 / 1048576) * 8;
$ingps = $inmbps / 1024;
$ingps1 = $outmbps / 1024;
?>
Example #6
0
 /**
  * Function walks through SNMP object id and returns result in array,
  * or returns false of call failed
  *
  * @param string $snmpObjectId
  * @return array
  * @throws Exception if IP address is not set
  * @throws Exception if $snmpObjectId is not in string format
  */
 public function walk($snmpObjectId)
 {
     /**
      * Check if IP address is set
      */
     if ($this->ip === null) {
         require_once 'Exception.php';
         throw new Kohut_SNMP_Exception('IP address was not set.');
     }
     /**
      * Check if SNMP object ID is in string format
      */
     if (!is_string($snmpObjectId)) {
         require_once 'Exception.php';
         throw new Kohut_SNMP_Exception('SNMP Object ID is not string.');
     }
     return @snmpwalk($this->ip, 'public', $snmpObjectId, $this->maxTimeout);
 }
Example #7
0
 private function _sGetCpuInfo($sIp)
 {
     $cpuinfo = array();
     $ret = snmpwalk($sIp, $this->_aConf['community'], 'hrDeviceEntry', 300000);
     if (is_array($ret)) {
         $len = 0;
         foreach ($ret as $k => $v) {
             list($t, $s) = explode(':', $v);
             if ('INTEGER' !== $t) {
                 $len = $k;
                 break;
             }
         }
         for ($i = 0; $i < $len; $i++) {
             list($t, $s) = explode(':', $ret[$len + $i], 2);
             if (' HOST-RESOURCES-TYPES::hrDeviceProcessor' == $s) {
                 list($t, $s) = explode(':', $ret[2 * $len + $i], 2);
                 $cpuinfo[trim($s)]++;
             }
         }
     }
     $ret = array();
     foreach ($cpuinfo as $k => $v) {
         $ret[] = $v . '个逻辑CPU,' . $k;
     }
     return implode(' || ', $ret);
 }
Example #8
0
    $swImage2UpdateDate_only = @snmpget($ip, $rcomm, ".1.3.6.1.4.1.171.10.94.89.89.2.16.1.1.7.1", $timeout, $retries);
    $swImage2UpdateDate_only = str_ireplace(chr(34), '', $swImage2UpdateDate_only);
    $swImage2UpdateDate_only = trim($swImage2UpdateDate_only);
    $swImage2UpdateTime_only = @snmpget($ip, $rcomm, ".1.3.6.1.4.1.171.10.94.89.89.2.16.1.1.9.1", $timeout, $retries);
    $swImage2UpdateTime_only = str_ireplace(chr(34), '', $swImage2UpdateTime_only);
    $swImage2UpdateTime_only = trim($swImage2UpdateTime_only);
    $swImage2UpdateTime = $swImage2UpdateDate_only . ' ' . $swImage2UpdateTime_only;
    // Пользователь, обновивший прошивку 1
    $swImage1SendUser = '';
    // Пользователь, обновивший прошивку 2
    $swImage2SendUser = '';
}
//Блок описания коммутатора для 3026
if ($ModelType == 'DES-3026') {
    //Root Port для 3026 (может и не найтись)
    $swRootPort = @snmpwalk($ip, $rcomm, ".1.3.6.1.4.1.171.11." . $p_oid[$ModelType] . ".2.16.4.1.4", $timeout, $retries);
    //Собственно поиск Root порта
    for ($pi = 0; $pi < $portscount[$ModelType]; $pi++) {
        if ($swRootPort[$pi] == 4) {
            $sysRootPort = $pi + 1;
        }
    }
    if ($sysRootPort == "") {
        $sysRootPort = "None";
    }
    //Определение MAC-адреса устройства
    $swIfIndex = @snmpget($ip, $rcomm, ".1.3.6.1.2.1.4.20.1.2." . $ip, $timeout, $retries);
    $sysMACaddr = @snmpget($ip, $rcomm, ".1.3.6.1.2.1.4.22.1.2." . $swIfIndex . "." . $ip, $timeout, $retries);
    $sysMACaddr = str_ireplace(chr(34), '', $sysMACaddr);
    $sysMACaddr = trim($sysMACaddr);
    $sysMACaddr = str_replace(' ', ':', $sysMACaddr);
    $ifOperStatusb = snmpwalk("{$hostfb}", "{$community}", "interfaces.ifTable.ifEntry.ifOperStatus");
    $ifLastChangeb = snmpwalk("{$hostfb}", "{$community}", "interfaces.ifTable.ifEntry.ifLastChange");
    $ipRouteNextHopb = snmpwalk("{$hostf}", "{$community}", "ipRouteNextHop");
    $ipNetToMediaNetAddressb = snmpwalk("{$hostfb}", "{$community}", "ipNetToMediaNetAddress");
    $ipRouteDestb = snmpwalk("{$hostfb}", "{$community}", "ipRouteDest");
    $ipRouteTypeb = snmpwalk("{$hostfb}", "{$community}", "ipRouteType");
    $nextb = snmp2_walk("{$hostfb}", "{$community}", ".1.3.6.1.4.1.9.9.23.1.2.1.1.6");
    $nameb = snmp2_walk("{$hostfb}", "{$community}", "1.3.6.1.2.1.1.5");
    $inoctetsb = snmpwalk("{$hostfb}", "{$community}", "1.3.6.1.2.1.2.2.1.10");
    $outoctetsb = snmpwalk("{$hostfb}", "{$community}", "1.3.6.1.2.1.2.2.1.16");
    $mac = snmpwalk("{$hostfb}", "{$community}", ".1.3.6.1.2.1.3.1.1.2");
    $sysb = substr($sysDescrb, 8, 15);
    $name1b = substr($nameb[0], 8, 50);
    $ipNetToMediaNetphysAddressb = snmpwalk("{$hostfb}", "{$community}", "1.3.6.1.2.1.2.2.1.6");
    $ipNetToMediaTypeb = snmpwalk("{$hostfb}", "{$community}", "1.3.6.1.2.1.4.22.1.4");
    $tempb = snmpwalk("{$hostfb}", "{$community}", "1.3.6.1.4.1.9.9.13.1.3.1.3");
    ///////////////////////////////////////////////////////////////////////////////////////////////
    $n = 0;
    for ($n = 0; $n < count($ifIndexb); $n++) {
        $sql9physb = mysql_query("INSERT INTO mac(interface,mac,hostname,hostip,id) VALUES ('{$ipNetToMediaNetAddressb[$n]}','{$ipNetToMediaNetphysAddressb[$n]}','{$name1b}','{$ipNetToMediaTypeb[$n]}','{$n}')");
    }
    for ($i = 0; $i < count($ifIndexb); $i++) {
        $cb = count($ifIndexb);
        $p = $i + 1;
        $tempb1 = substr($tempb[0], 8, 12);
        $sql4 = mysql_query("INSERT INTO hosts(ifindex,ifdescr,ifoperstatus,host,sysdescr,ip,inoctets,outoctets,cpu,idinterface,temp) VALUES ('{$ifIndexb[$i]}','{$ifDescrb[$i]}','{$ifOperStatusb[$i]}','{$name1b}','{$sysDescrb}','{$hostfb}','{$inoctetsb[$i]}','{$outoctetsb[$i]}','{$cb}','{$p}','{$tempb1}')");
    }
    $sql1012 = mysql_query("INSERT INTO node(iphost,adjacencies,host) VALUES('{$name1b}','1','1')");
}
//////////////Remplir les fichiers des @ mac des interfaces///////////////////////
function my_exec($cmd, $input = '')
    $q = 'empty';
} else {
    $q = $_GET['q'];
}
if (empty($_GET['i'])) {
    $i = 'Select a device';
} else {
    $i = $_GET['i'];
}
$result = mysql_query("SELECT * FROM hosts WHERE host like '%{$q}%'");
while ($row = mysql_fetch_array($result)) {
    $ip = $row['ip'];
    $s = $row['ifdescr'];
}
$community = 'public';
$temp1 = snmpwalk("{$ip}", "{$community}", "1.3.6.1.4.1.9.9.13.1.3.1.3");
$temp = substr($temp1[0], 8, 12);
$result1 = mysql_query("SELECT * FROM hosts WHERE host like '%{$q}%' and idinterface = '" . $i . "'");
while ($row1 = mysql_fetch_array($result1)) {
    $interf = $row1['ifoperstatus'];
    $inoctets = $row1['inoctets'];
    $outoctets = $row1['outoctets'];
    $ifdescr = $row1['ifdescr'];
    //$temp=$row1['temp'];
}
$inoctets1 = substr($inoctets, 10, 17);
$outoctets1 = substr($outoctets, 10, 17);
$ifdescr1 = substr($ifdescr, 7, 17);
?>

                            
Example #11
0
$host = '10.255.255.253';
$community = 'cf-read';
$result_desc = snmpwalk($host, $community, 'IF-MIB::ifDescr');
$result_status = snmpwalk($host, $community, 'IF-MIB::ifOperStatus');
$result_speed = snmpwalk($host, $community, 'IF-MIB::ifSpeed');
$result_admin = snmpwalk($host, $community, 'IF-MIB::ifAdminStatus');
$result_in_start = snmpwalk($host, $community, 'IF-MIB::ifInOctets');
sleep(1);
$result_in_end = snmpwalk($host, $community, 'IF-MIB::ifInOctets');
$result_out_start = snmpwalk($host, $community, 'IF-MIB::ifOutOctets');
sleep(1);
$result_out_end = snmpwalk($host, $community, 'IF-MIB::ifOutOctets');
$result_error_out = snmpwalk($host, $community, 'IF-MIB::ifOutErrors');
$result_error_in = snmpwalk($host, $community, 'IF-MIB::ifInErrors');
$result_ucast_out = snmpwalk($host, $community, 'IF-MIB::ifOutNUcastPkts');
$result_ucast_in = snmpwalk($host, $community, 'IF-MIB::ifInNUcastPkts');
$ports = count($result_desc);
$switch = array();
for ($i = 0; $i < $ports; $i++) {
    $port = new stdClass();
    $port->desc = format($result_desc[$i]);
    $port->status = format($result_status[$i]);
    $port->speed = format($result_speed[$i]) / 1000000 . ' MB';
    $port->admin = format($result_admin[$i]);
    $port->traffic_in = getRealSize((format($result_in_end[$i]) - format($result_in_start[$i])) * 8);
    $port->traffic_out = getRealSize((format($result_out_end[$i]) - format($result_out_start[$i])) * 8);
    $port->error = format($result_error_out[$i]) + format($result_error_in[$i]);
    $port->ucast = format($result_ucast_out[$i]) + format($result_ucast_in[$i]);
    $port->time = time();
    array_push($switch, $port);
}
var_dump(snmp2_walk($hostname, $community, '.1.3.6.1.2.1.1', $timeout, ''));
echo "Checking working\n";
echo "Single OID\n";
$return = snmp2_walk($hostname, $community, '.1.3.6.1.2.1.1', $timeout, $retries);
var_dump(gettype($return));
var_dump(sizeof($return));
var_dump(gettype($return[0]));
var_dump(gettype($return[1]));
echo "Single OID in array\n";
$return = snmp2_walk($hostname, $community, array('.1.3.6.1.2.1.1'), $timeout, $retries);
var_dump(gettype($return));
var_dump(gettype($return[0]));
echo "Default OID\n";
$return = snmpwalk($hostname, $community, '', $timeout, $retries);
var_dump(gettype($return));
var_dump(gettype($return[0]));
echo "More error handling\n";
echo "Single incorrect OID\n";
$return = snmpwalk($hostname, $community, '.1.3.6...1', $timeout, $retries);
var_dump($return);
echo "Multiple correct OID\n";
$return = snmp2_walk($hostname, $community, array('.1.3.6.1.2.1.1', '.1.3.6'), $timeout, $retries);
var_dump($return);
echo "Multiple OID with wrong OID\n";
$return = snmp2_walk($hostname, $community, array('.1.3.6.1.2.1.1', '.1.3.6...1'), $timeout, $retries);
var_dump($return);
$return = snmp2_walk($hostname, $community, array('.1.3.6...1', '.1.3.6.1.2.1.1'), $timeout, $retries);
var_dump($return);
echo "Single nonexisting OID\n";
$return = snmp2_walk($hostname, $community, array('.1.3.6.99999.0.99999.111'), $timeout, $retries);
var_dump($return);
<?php

/**
Consulta o status do tráfego da rede para o I.P da sessão e retorna no formato para ser lido pelo gráfico.
Como a informação de in e out são do tipo COunter32 preciso comparar os resultados com coleta anterior.
*/
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
session_start();
$ip = $_SESSION["ip"];
//Capturar dados atuais da placa de rede
$in_network = snmpwalk($ip, "public", "1.3.6.1.2.1.2.2.1.10.2");
//interface de rede sempre fixa
$in_network_int = (int) str_replace("Counter32: ", "", $in_network[0]);
$out_network = snmpwalk($ip, "public", "1.3.6.1.2.1.2.2.1.16.2");
//interface de rede sempre fixa
$out_network_int = (int) str_replace("Counter32: ", "", $out_network[0]);
/*
echo '<pre>';
var_dump($_SESSION);
echo '</pre>';
*/
//Se ja teve uma captura anterior
if (isset($_SESSION['last_check']) && !empty($_SESSION['last_check'])) {
    //Capturar variaveis da sessão de captura anterior
    $last_in_network = $_SESSION["last_in"];
    $last_out_network = $_SESSION["last_out"];
    $last_check_network = $_SESSION["last_check"];
    $data_sessao = new DateTime($last_check_network);
    $agora = new DateTime();
    $duration = $agora->diff($data_sessao);
Example #14
0
 /**
  * Do snmpwalk
  *
  * @param unknown_type $rootOID
  * @return array Array of values
  */
 public function getTree($rootOID = null)
 {
     $retval = @snmpwalk("{$this->host}:{$this->port}", $this->community, $rootOID, $this->timeout);
     return $retval;
 }
Example #15
0
<?php

/**
Consulta o status da CPU para o I.P da sessão e retorna no formato para ser lido pelo gráfico.
*/
session_start();
$ip = $_SESSION["ip"];
$cpu_used = snmpwalk($ip, "public", "1.3.6.1.2.1.25.3.3.1");
preg_match_all('!\\d+!', $cpu_used[1], $matches);
//somente numeros
$var = implode(' ', $matches[0]);
//copiadoarray para variavl
echo "&label=" . date('H:i:s') . "&value=" . $var;
Example #16
0
 /**
  * @access private
  */
 function _walkget($oid)
 {
     $ret = snmpwalk($this->host, $this->community, $oid);
     if (sizeof($ret) > 0) {
         return $ret[0];
     } else {
         return false;
     }
 }
Example #17
0
 function WIFI_GetAllSignal($ip, $community)
 {
     $tx_bytes_snmp = @snmpwalkoid($ip, $community, ".1.3.6.1.4.1.14988.1.1.1.2.1.3");
     $i = 0;
     $devices = array();
     if (is_array($tx_bytes_snmp)) {
         $oid_tx_rate = '.1.3.6.1.4.1.14988.1.1.1.2.1.8';
         $oid_rx_rate = '.1.3.6.1.4.1.14988.1.1.1.2.1.9';
         $oid_tx_packets = '.1.3.6.1.4.1.14988.1.1.1.2.1.6';
         $oid_rx_packets = '.1.3.6.1.4.1.14988.1.1.1.2.1.7';
         $oid_tx_bytes = '.1.3.6.1.4.1.14988.1.1.1.2.1.4';
         $oid_rx_bytes = '.1.3.6.1.4.1.14988.1.1.1.2.1.5';
         while (list($indexOID, $rssi) = each($tx_bytes_snmp)) {
             $oidarray = explode(".", $indexOID);
             $end_num = count($oidarray);
             $mac = "";
             for ($counter = 2; $counter < 8; $counter++) {
                 $temp = dechex($oidarray[$end_num - $counter]);
                 if ($oidarray[$end_num - $counter] < 16) {
                     $temp = "0" . $temp;
                 }
                 if ($counter == 7) {
                     $mac = $temp . $mac;
                 } else {
                     $mac = ":" . $temp . $mac;
                 }
             }
             if ($txr = @snmpwalk($ip, $community, $oid_tx_rate)) {
                 $txr = str_replace("Gauge32:", "", $txr[$i]);
                 $devices[$i]['tx_rate'] = $txr / 1000000;
             } else {
                 $devices[$i]['tx_rate'] = 0;
             }
             if ($rxr = @snmpwalk($ip, $community, $oid_rx_rate)) {
                 $rxr = str_replace("Gauge32:", "", $rxr[$i]);
                 $devices[$i]['rx_rate'] = $rxr / 1000000;
             } else {
                 $devices[$i]['rx_rate'] = 0;
             }
             if ($txp = @snmpwalk($ip, $community, $oid_tx_packets)) {
                 $txp = str_replace("Counter32:", "", $txp[$i]);
                 $devices[$i]['tx_packets'] = $txp;
             } else {
                 $devices[$i]['tx_packets'] = 0;
             }
             if ($rxp = @snmpwalk($ip, $community, $oid_rx_packets)) {
                 $rxp = str_replace("Counter32:", "", $rxp[$i]);
                 $devices[$i]['rx_packets'] = $rxp;
             } else {
                 $devices[$i]['rx_packets'] = 0;
             }
             if ($txb = @snmpwalk($ip, $community, $oid_tx_bytes)) {
                 $txb = str_replace("Counter32:", "", $txb[$i]);
                 $devices[$i]['tx_bytes'] = $txb;
             } else {
                 $devices[$i]['tx_bytes'] = 0;
             }
             if ($rxb = @snmpwalk($ip, $community, $oid_rx_bytes)) {
                 $rxb = str_replace("Counter32:", "", $rxb[$i]);
                 $devices[$i]['rx_bytes'] = $rxb;
             } else {
                 $devices[$i]['rx_bytes'] = 0;
             }
             $devices[$i]['rx_signal'] = str_replace("INTEGER:", "", $rssi);
             $devices[$i]['mac'] = strtoupper($mac);
             $i++;
         }
     }
     return $devices;
 }
Example #18
0
<?php

$host = '10.255.255.247';
$community = 'cf-read';
$object_id = 'IF-MIB::ifDescr';
$object_id1 = 'IF-MIB::ifInOctets';
$sysdesc = snmpwalk($host, $community, $object_id1);
$t1 = microtime(true);
sleep(1);
$sysdesc1 = snmpwalk($host, $community, $object_id1);
$t2 = microtime(true);
echo '耗时' . round($t2 - $t1, 3) . '秒';
$oid = snmpwalk($host, $community, $object_id);
echo $sysdesc1[5] . '\\n' . $sysdesc[5];
print_r((format($sysdesc1[5]) - format($sysdesc[5])) * 8 / 1024 / 1024);
print_r($oid[5]);
function format($result)
{
    if (!$result) {
        return false;
    }
    if (is_array($result)) {
        $result = array_shift($result);
    }
    $result = str_replace('STRING: ', '', $result);
    $result = str_replace('INTEGER: ', '', $result);
    $result = str_replace('Counter32: ', '', $result);
    $result = str_replace('Gauge32: ', '', $result);
    return $result;
}
//$a = snmpwalkoid("127.0.0.1", "public", "");
Example #19
0
<?php

/**
Consulta o status da Memória para o I.P da sessão e retorna no formato para ser lido pelo gráfico.
Multiplica por 1024 que é o allocationUnits
*/
session_start();
$ip = $_SESSION["ip"];
$phsycal_memory_used = snmpwalk($ip, "public", "1.3.6.1.2.1.25.2.3.1.6.1");
preg_match_all('!\\d+!', $phsycal_memory_used[0], $matches);
//somente numeros
$var = implode(' ', $matches[0]);
//copiadoarray para variavl
echo "&label=" . date('H:i:s') . "&value=" . (int) $var * 1024;
Example #20
0
echo $up5;
?>
			</h5>
		</div>
		<div class="col-sm-4 r6">
			<div>
				<h1>
					<?php 
$name6 = snmpget("10.4.160.1", "public", ".1.3.6.1.2.1.1.5.0");
echo $name6;
?>
				</h1>
			</div>
			<h3>
				<?php 
$r415 = snmpwalk('10.41.160.1', 'public', '.1.3.6.1.2.1.4.20.1.1');
$c6 = count($r415);
//echo $c1;
//echo $f1[0];
for ($i = 0; $i < $c6; $i++) {
    echo $r415[$i];
    echo '<br>';
}
?>
			</h3>
			<h4>detail</h4>
			<h5>

			<?php 
$system6 = snmpget("10.41.160.1", "public", ".1.3.6.1.2.1.1.1.0");
echo $system6;
Example #21
0
    echo $nokmsg;
    die;
}
$_GET = sanitize($_GET);
?>
<html><body bgcolor=#887766>
<h2><?php 
echo $_GET['ip'];
?>
 (<?php 
echo $_GET['c'];
?>
)</h2>
<img src=../img/32/bdwn.png hspace=10><b><?php 
echo $_GET['oid'];
?>
</b>
<pre style="background-color:#998877">
<?php 
if ($_GET['ip'] and $_GET['ip'] and $_GET['ip'] and $_GET['oid']) {
    foreach (snmpwalk($_GET['ip'], $_GET['c'], $_GET['oid']) as $val) {
        echo "{$val}<br>\n";
    }
} else {
    echo $resmsg;
}
?>
</pre>
</body>
</html>
 function walk($oid, $suffix_as_key = FALSE)
 {
     switch ($this->version) {
         case self::VERSION_1:
             if ($suffix_as_key) {
                 $this->result = snmpwalk($this->host, $this->community, $oid);
             } else {
                 $this->result = snmprealwalk($this->host, $this->community, $oid);
             }
             break;
         case self::VERSION_2C:
         case self::VERSION_2c:
             if ($suffix_as_key) {
                 $this->result = snmp2_walk($this->host, $this->community, $oid);
             } else {
                 $this->result = snmp2_real_walk($this->host, $this->community, $oid);
             }
             break;
         case self::VERSION_3:
             if ($suffix_as_key) {
                 $this->result = snmp3_walk($this->host, $this->community, $this->sec_level, $this->auth_protocol, $this->auth_passphrase, $this->priv_protocol, $this->priv_passphrase, $oid);
             } else {
                 $this->result = snmp3_real_walk($this->host, $this->community, $this->sec_level, $this->auth_protocol, $this->auth_passphrase, $this->priv_protocol, $this->priv_passphrase, $oid);
             }
             break;
     }
     return $this->result;
 }
Example #23
0
<?php

$start = microtime(true);
/*
ini_set('display_errors', 1);
ini_set('display_errors','On');*/
define('IPMANAGER', true);
define('ROOT_DIR', realpath(dirname(__FILE__) . "/../.."));
define('ENGINE_DIR', ROOT_DIR . '/root');
require_once ENGINE_DIR . '/config/config.php';
require_once ENGINE_DIR . '/classes/class.array2xml.php';
$date = date("Y-m-d H:i:s");
$host = $CONFIG['snmphost'];
$community = "public";
$object_id = "1.3.6.1.2.1.4.22.1.3";
$sysdesc = snmpwalk($host, $community, $object_id);
//print_r($sysdesc);
$ips = array();
$xmlStr2 = file_get_contents($command['ipdatefile']);
$array2 = json_decode(json_encode((array) simplexml_load_string($xmlStr2)), 1);
foreach ($sysdesc as $rowSNMP) {
    $rowSNMP = str_replace("\n", "", substr($rowSNMP, 11));
    //if( $rowSNMP[0].$rowSNMP[1].$rowSNMP[2]=="192") echo "yes"; else echo "no";
    //if( substr($rowSNMP,0,9)=="192.168.1" )
    //$sps=substr($rowSNMP,12);
    //if( in_array(substr($rowSNMP,8,3),$_HOSTEL_NETS) && $sps!=="1" && $sps!=="0" && $sps!=="255")
    //{
    $rowSNMP_s = "k" . str_replace(".", "", $rowSNMP);
    $ips[$rowSNMP_s] = array();
    //IpAddress:
    //if(!file_exists("./ipdate/".$rowSNMP.".ip")) file_put_contents("./ipdate/".$rowSNMP.".ip","{$rowSNMP}  {$date}");
var_dump(snmpwalk($hostname, $community, '.1.3.6.1.2.1.1', $timeout, ''));
echo "Checking working\n";
echo "Single OID\n";
$return = snmpwalk($hostname, $community, '.1.3.6.1.2.1.1', $timeout, $retries);
var_dump(gettype($return));
var_dump(sizeof($return));
var_dump(gettype($return[0]));
var_dump(gettype($return[1]));
echo "Single OID in array\n";
$return = snmpwalk($hostname, $community, array('.1.3.6.1.2.1.1'), $timeout, $retries);
var_dump(gettype($return));
var_dump(gettype($return[0]));
echo "Default OID\n";
$return = snmpwalk($hostname, $community, '', $timeout, $retries);
var_dump(gettype($return));
var_dump(gettype($return[0]));
echo "More error handling\n";
echo "Single incorrect OID\n";
$return = snmpwalk($hostname, $community, '.1.3.6...1', $timeout, $retries);
var_dump($return);
echo "Multiple correct OID\n";
$return = snmpwalk($hostname, $community, array('.1.3.6.1.2.1.1', '.1.3.6'), $timeout, $retries);
var_dump($return);
echo "Multiple OID with wrong OID\n";
$return = snmpwalk($hostname, $community, array('.1.3.6.1.2.1.1', '.1.3.6...1'), $timeout, $retries);
var_dump($return);
$return = snmpwalk($hostname, $community, array('.1.3.6...1', '.1.3.6.1.2.1.1'), $timeout, $retries);
var_dump($return);
echo "Single nonexisting OID\n";
$return = snmpwalk($hostname, $community, array('.1.3.6.99999.0.99999.111'), $timeout, $retries);
var_dump($return);
Example #25
0
                    $sql = "INSERT INTO `statetrank` (device_id, port, date, state_id) VALUES ('{$rowsql['0']}','{$i}','{$today}','2')";
                    $change_trank = mysql_query($sql);
                }
            }
            /* Само состояние порта */
            if ($strprst == "up") {
                $sql = "UPDATE ports SET trank=1 WHERE device_id={$rowsql['0']} AND port={$i}";
                $state_trank = mysql_query($sql);
            } else {
                $sql = "UPDATE ports SET trank=2 WHERE device_id={$rowsql['0']} AND port={$i}";
                $state_trank = mysql_query($sql);
            }
        } else {
            $sql = "UPDATE ports SET trank=0 WHERE device_id={$rowsql['0']} AND port={$i}";
            $state_ports = mysql_query($sql);
        }
    }
    /* Получить кол-во mac на всех портах свитча */
    $getmac = snmpwalk("{$rowsql['2']}", "public", ".1.3.6.1.2.1.17.4.3.1.2.0");
    /* Почучить данные с масива и кол-во повторений */
    $arr = array_count_values($getmac);
    if (is_array($arr)) {
        reset($arr);
        while (list($k, $v) = each($arr)) {
            $a = substr($k, 9, strlen($k) - 9);
            /* Обновить кол-во MAC на порту */
            $sql = "UPDATE ports SET mac='{$v}' WHERE device_id={$rowsql['0']} AND port={$a}";
            $mac = mysql_query($sql);
        }
    }
}
Example #26
0
 function my_snmp_walk($ip, $credentials, $oid)
 {
     $timeout = '30000000';
     $retries = '0';
     switch ($credentials->credentials->version) {
         case '1':
             $array = @snmpwalk($ip, $credentials->credentials->community, $oid, $timeout, $retries);
             break;
         case '2':
             $array = @snmp2_walk($ip, $credentials->credentials->community, $oid, $timeout, $retries);
             break;
         case '3':
             $sec_name = $credentials->credentials->security_name ?: '';
             $sec_level = $credentials->credentials->security_level ?: '';
             $auth_protocol = $credentials->credentials->authentication_protocol ?: '';
             $auth_passphrase = $credentials->credentials->authentication_passphrase ?: '';
             $priv_protocol = $credentials->credentials->privacy_protocol ?: '';
             $priv_passphrase = $credentials->credentials->privacy_passphrase ?: '';
             $array = @snmp3_walk($ip, $sec_name, $sec_level, $auth_protocol, $auth_passphrase, $priv_protocol, $priv_passphrase, $oid, $timeout, $retries);
             break;
         default:
             return false;
             break;
     }
     if (!is_array($array)) {
         return false;
     }
     foreach ($array as $i => $value) {
         $array[$i] = trim($array[$i]);
         if ($array[$i] == '""') {
             $array[$i] = '';
         }
         if (strpos($array[$i], '.') === 0) {
             $array[$i] = substr($array[$i], 1);
         }
         // remove the first and last characters if they are "
         if (substr($array[$i], 0, 1) == "\"") {
             $array[$i] = substr($array[$i], 1, strlen($array[$i]));
         }
         if (substr($array[$i], -1, 1) == "\"") {
             $array[$i] = substr($array[$i], 0, strlen($array[$i]) - 1);
         }
         // remove some return strings
         if (strpos(strtolower($array[$i]), '/etc/snmp') !== false or strpos(strtolower($array[$i]), 'no such instance') !== false or strpos(strtolower($array[$i]), 'no such object') !== false or strpos(strtolower($array[$i]), 'not set') !== false or strpos(strtolower($array[$i]), 'unknown value type') !== false) {
             $array[$i] = '';
         }
         // remove any quotation marks
         $array[$i] = str_replace('"', ' ', $array[$i]);
         // replace any line breaks with spaces
         $array[$i] = str_replace(array("\r", "\n"), " ", $array[$i]);
     }
     return $array;
 }
Example #27
-1
    // Описание портов
    $portDescription = @snmpwalk($ip, $rcomm, ".1.3.6.1.4.1.171.11." . $p_oid[$ModelType] . ".2.2.2.1.6", $timeout, $retries);
    for ($pi = 1; $pi < $portscount[$ModelType] + 1; $pi++) {
        $portDescription[$pi - 1] = str_ireplace(' ', '', $portDescription[$pi - 1]);
        $portDescription[$pi - 1] = str_ireplace('"', '', $portDescription[$pi - 1]);
        $portDescription[$pi - 1] = str_ireplace('00', '', $portDescription[$pi - 1]);
        $portDescription[$pi - 1] = str_ireplace(chr(10), '', $portDescription[$pi - 1]);
        $portDescription[$pi - 1] = str_ireplace(chr(9), '', $portDescription[$pi - 1]);
        if ($ModelType != 'DES-3200-28') {
            $portDescription[$pi - 1] = hextostr($portDescription[$pi - 1]);
        }
    }
}
if ($ModelType == 'DES-3526' || $ModelType == 'DES-3026' || $ModelType == 'DGS-3100-24TG') {
    // Описание портов
    $portDescription = @snmpwalk($ip, $rcomm, ".1.3.6.1.2.1.31.1.1.1.18", $timeout, $retries);
}
for ($pi = 1; $pi < $portscount[$ModelType] + 1 - $nocomboports; $pi++) {
    $kport = $pi;
    if (strlen($kport) == 1) {
        $kport = "0" . $kport;
    }
    if ($portscount[$ModelType] == 30) {
        if ($kport == 26) {
            $kport = "25(F)";
        }
        if ($kport == 27) {
            $kport = "26";
        }
        if ($kport == 28) {
            $kport = "26(F)";
Example #28
-1
</form>
<?php 
/* VLAN  */
//echo "<h4>VLAN порта:</h4>";
$vlan = array(101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 114, 115, 172, 173, 184, 185);
for ($y = 0; $y <= count($vlan) - 1; $y++) {
    $numvlan = snmpget("{$row['0']}", "public", "{$row['2']}.{$vlan[$y]}");
    if (ereg("1", $numvlan)) {
        $vl = $vlan[$y];
        //echo "VLAN: $vl\n";
    }
}
/* MAC */
echo "<font color=green><h4>MAC-адрес:</h4></font>\n";
$getprt = snmpwalk("{$row['0']}", "public", ".1.3.6.1.2.1.17.4.3.1.2");
$getmac = snmpwalk("{$row['0']}", "public", ".1.3.6.1.2.1.17.4.3.1.1");
for ($i = 0; $i <= count($getprt) - 1; $i++) {
    $prt = substr($getprt[$i], 9, strlen($getprt[$i]) - 9);
    if ($prt == $port) {
        $strmac = substr($getmac[$i], 12, 17);
        $mac = str_replace(' ', ':', $strmac);
        echo "{$mac}<br />\n";
    }
}
/* port security max-mac-coumnt */
echo "<font color=green><h4>Контроль MAC:</h4></font>\n";
$maxcount = snmpget("{$row['0']}", "public", "{$row['3']}.{$port}");
if (ereg("1", $maxcount) || ereg("2", $maxcount)) {
    print "<a href=\"mac.php?id={$id}&port={$port}&maxoff\"><b>[2.Очистить]</b></a>";
} else {
    print "<a href=\"mac.php?id={$id}&port={$port}&maxon\"><b>[Включить] </b></a>";
Example #29
-1
<?php

/**
Consulta o nº de processos para o I.P da sessão e retorna no formato para ser lido pelo gráfico.
*/
session_start();
$ip = $_SESSION["ip"];
$num_processes = snmpwalk($ip, "public", "1.3.6.1.2.1.25.1.6");
echo "&label=" . date('H:i:s') . "&value=" . str_replace("Gauge32: ", '', $num_processes[0]);
Example #30
-2
}
if (isset($_POST['read']) or $read == "read") {
    if (isset($_POST['read'])) {
        $device_IP = $_POST['device_IP'];
    }
    $_SESSION['device_IP_sr'] = $device_IP;
    $_SESSION['read_sr'] = "read";
    //    Board Information
    $hardwareVersion = substr(snmp2_get($device_IP, "public", $oid['hardwareVersion']), 9);
    $fpgaVersion = substr(snmp2_get($device_IP, "public", $oid['fpgaVersion']), 9);
    $softwareVersion = substr(snmp2_get($device_IP, "public", $oid['softwareVersion']), 9);
    $serialNumber = substr(snmp2_get($device_IP, "public", $oid['serialNumber']), 9);
    //system info
    include_once 'info_function.php';
    // Interfaces
    $interfaces_walk = snmpwalk($device_IP, "public", "1.3.6.1.2.1.2.2");
    foreach ($interfaces_walk as $key => $value) {
        $interfaces[] = strstr($interfaces_walk[$key], " ");
    }
    //    RF1
    $tunerStatus1 = substr(snmp2_get($device_IP, "public", $oid['tunerStatus1']), 9);
    if ($tunerStatus1 == "0" or $_GET['admin'] == "1") {
        $frequency1 = substr(snmp2_get($device_IP, "public", $oid['frequency1']), 9) / 1000;
        $esno1 = substr(snmp2_get($device_IP, "public", $oid['esno1']), 9) / 10;
        $powerLevel1 = substr(snmp2_get($device_IP, "public", $oid['powerLevel1']), 9) / 10;
        $ber1 = substr(snmp2_get($device_IP, "public", $oid['ber1']), 9);
        $frequencyOffset1 = substr(snmp2_get($device_IP, "public", $oid['frequencyOffset1']), 9) / 1000;
        $badPacketCount1 = substr(snmp2_get($device_IP, "public", $oid['badPacketCount1']), 9);
        $modcodStatus1 = substr(snmp2_get($device_IP, "public", $oid['modcodStatus1']), 9);
        $rollOffStatus1 = substr(snmp2_get($device_IP, "public", $oid['rollOffStatus1']), 9);
        $pilotsStatus1 = substr(snmp2_get($device_IP, "public", $oid['pilotsStatus1']), 9);