读书人

关于使用snmp++返回“SNMP request ti

发布时间: 2013-07-09 09:50:47 作者: rapoo

关于使用snmp++返回“SNMP request timed out”错误
本帖最后由 wjling2009 于 2011-03-28 15:15:53 编辑 大家好!我现在在做一些snmp++的编程工作,链接的工作已经没问题了,在使用的时候一直报错得不到结果。在我的电脑上SNMP服务已经开启,并且SNMP Service属性卡中的“安全”等内容也已经设置,服务也已经开启,有snmp.exe和snmptrap.exe进程运行。
我想问的是,除了开启SNMP服务外,我还需要做那些工作才能使程序正常运行?我在agentpp.com网站上看到还有agent++,我需要搞这个吗。。?接触SNMP时间不长,还望有人帮忙解惑!下面是代码还有输出



#include "stdafx.h"
#include "snmp_pp.h"

using namespace std;



int _tmain(int argc, _TCHAR* argv[])
{

Snmp::socket_startup();
snmp_version version=version1;
int status;
Snmp snmp(status,0,false);
Vb vb;
vb.set_oid((Oid)"1.3.6.1.2.1.1.2");
Pdu pdu;
pdu+=vb;

UdpAddress address("127.0.0.1:161");

CTarget target(address);
target.set_version(version);
target.set_retry(1);
target.set_timeout(500);
target.set_readcommunity("public");

SnmpTarget *starget=NULL;
starget=⌖

status=snmp.get(pdu,*starget);

if(status==SNMP_CLASS_SUCCESS)
{
pdu.get_vb(vb,0);
string reply_oid=vb.get_printable_oid();
string reply_value=vb.get_printable_value();
cout<<reply_oid<<" :"<<reply_value<<endl;
}
else
cout<<snmp.error_msg(status)<<endl;

Snmp::socket_cleanup();


system("pause");
return 0;
}


输出:
20110328.15:12:26: 5440: (4)DEBUG : SNMPMessage: return value for build message: (0)
SNMP++: SNMP request timed out

还烦请解释下输出的含义及原因!
谢谢!
[解决办法]
检查下是不是防火墙的原因
[解决办法]
帮你测试了下,是可以的,结果如下:
20110329.19:10:56: 8700: (1)DEBUG : Initialized request_id to 1041.
20110329.19:10:56: 8700: (1)DEBUG : snmp_engine called with CTarget
20110329.19:10:56: 8700: (4)DEBUG : SNMPMessage: return value for build message
: (0)
20110329.19:10:56: 8700: (1)DEBUG : ++ SNMP++: sending to 127.0.0.1/161:


20110329.19:10:56: 8700: (3)DEBUG : 30 26 02 01 00 04 06 70 75 62 6C 69 63 A
0 19 02
20110329.19:10:56: 8700: (3)DEBUG : 02 04 12 02 01 00 02 01 00 30 0D 30 0B 0
6 07 2B
20110329.19:10:56: 8700: (3)DEBUG : 06 01 02 01 01 02 05 00
20110329.19:10:56: 8700: (1)DEBUG : ++ SNMP++: something received...
20110329.19:11:01: 8700: (1)DEBUG : ++ SNMP++: sending to 127.0.0.1/161:
20110329.19:11:01: 8700: (3)DEBUG : 30 26 02 01 00 04 06 70 75 62 6C 69 63 A
0 19 02
20110329.19:11:01: 8700: (3)DEBUG : 02 04 12 02 01 00 02 01 00 30 0D 30 0B 0
6 07 2B
20110329.19:11:01: 8700: (3)DEBUG : 06 01 02 01 01 02 05 00
20110329.19:11:01: 8700: (1)DEBUG : ++ SNMP++: something received...
20110329.19:11:06: 8700: (6)INFO : MsgQueue: Message timed out, removed id fro
m v3MP cache (rid): (1042)
SNMP++: SNMP request timed out
20110329.19:11:06: 8700: (1)DEBUG : WSACleanup: ReturnValue (0)
你再看看有没有配置方面的问题.
[解决办法]
netstat -an一下 看看161端口开启了没有

如果你的community配置不正确也会出现超时的问题

读书人网 >C++

热点推荐