2014-11-25 16 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