2014-11-25 15 views
0

所以我試圖在一個denkovi SNMP以太網控制器在php打開數字輸出。根據PHP手冊,這應該工作,但事實並非如此。因此,這裏是我的代碼,如果有人能幫助我:PHP snmpset錯誤

<?php 
    if($_GET["host"] && $_GET["port"] && $_GET["com"] && $_GET["oid"] && $_GET["status"]) 
    { 
    $host = $_GET['host']; //localhost 
    $ip = gethostbyname($host); 
    $port = $_GET['port']; //10161 
    $community = $_GET['com']; //private 
    $relenr = $_GET['oid']; // 10 
    $status = $_GET['status']; // 1 (turn it on) 
    $adress = $ip.":".$port; 
    $OID = ".1.3.6.1.4.1.19865.1.2.1.{$relenr}.0"; 
    if(snmpset($adress, $community, $OID, 'i', intval($status))== true) 
    { 
    echo "\n succes!"; 
    } 
    else 
    { 
    echo "\n error!!"; 
    } 

    } 
?> 
+0

你能提供額外的錯誤細節,參見http://php.net/manual/en/class.snmp.php#snmp.props.exceptions-enabled當你在命令行執行等效的net-snmp snmpset時會發生什麼?還有snmpget? – k1eran 2014-11-25 11:58:56

+0

with comman line: 'snmpset -v1 -c private localhost:10161.1.3.6.1.4.1.19865.1.2.1.10.0 i 1 SNMPv2-SMI :: enterprises.19865.1.2.1.10.0 = INTEGER:1' – WdarinS 2014-11-25 12:50:28

回答

0

試試這個,它的工作對我來說:

$host = "x.x.x.x:y" ; 
$community = "private" ; 
$oid = ".1.3.6.1.4.1.19865.1.2.2.1.0" ; 
$type = "i" ; 
$value = 1 ; 
if(snmpset($host, $community, $oid , $type , $value)){ 
    echo "ok"; 
} 
else{ 
    echo "error"; 
} 

也可以嘗試使用exec函數做到這一點:

exec('snmpset -v1 -cprivate x.x.x.x:y .1.3.6.1.4.1.19865.1.2.2.1.0 i 1',$output,$exitCode); 
print_r($output);//print the result 
echo $exitCode;//check if the snmpset return 0 == ok