Jump to content

SNMPset return values problem


alon.0101

Recommended Posts

Hi there,

 

I'm trying to change a port-state on a switch on/off and using the following code:

$ip = '10.0.0.1';

$oid = '.1.3.6.1.2.1.2.2.1.7.10';

$result = snmpset($ip,"RWaccess",$oid,"i","1",1000000,0);

echo $result;

this code works great, and the $result is "1".

but if the command fails (invalid ip or community for example), it won't return FALSE just displays the error:

Warning: snmpset() [function.snmpset]: No response from 10.0.0.1 in C:\wamp\www\test.php on line 9

 

How do i check if the command fails? i don't want that error msg...

Thanks in advance!

 

Alan.

Link to comment
https://forums.phpfreaks.com/topic/112542-snmpset-return-values-problem/
Share on other sites

Hi Ace,

 

thanks for your quick answer!

I tried to add die() and Or die() and i still get the warning message plus the error one...

$result = (snmpset($ip,"RWaccess",$oid,"i","1",1000000,0) or die("No Response: here is my custom error!"));
if($result != 1) { die("No Response: here is my custom error!"); }

 

Maybe i'm doing something wrong..

 

hmmm, interesting. I've never worked with this port stuff before. But that should of worked  :-\

 

try this:

<?php
$result = (snmpset($ip,"RWaccess",$oid,"i","1",1000000,0) or die("No Response: here is my custom error!"));

if($result == FALSE) { die("No Response: here is my custom error!"); }

 

let me know what you get.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.