[snmp++]读取MIB信息最简单的例子

snmp++自带例子

#include "stdafx.h"
#include <snmp_pp.h>
#include <iostream.h>
//#define SYSDESCR "1.3.6.1.2.1.1.5.0" // Object ID for System Descriptor
void main()
{
Snmp::socket_startup();
int status; // return status
CTarget ctarget( (IpAddress) "192.168.15.175");// SNMP++ v1 target
Vb vb("1.3.6.1.2.1.1.1.0");// SNMP++ Variable Binding
Pdu pdu; // SNMP++ PDU

//-------[ Construct a SNMP++ SNMP Object ]---------------------------------------
Snmp snmp( status); // Create a SNMP++ session
if ( status != SNMP_CLASS_SUCCESS) { // check creation status
cout << snmp.error_msg( status); // if fail, print error string
return; }

//-------[ Invoke a SNMP++ Get ]-------------------------------------------------------
pdu += vb; // add the variable binding
if ( (status = snmp.get( pdu, ctarget)) != SNMP_CLASS_SUCCESS)
cout << snmp.error_msg( status);
else {
pdu.get_vb( vb,0); // extract the variable binding
cout << "System Descriptor = "<< vb.get_printable_value(); } // print out
Snmp::socket_cleanup();
cout<<"\n";
};


上面的192.168.15.175是一台xp,只需在这台机的控制面版-添加删除windows组件-管理和监视工具-把里面的两个都装上,就可以通过snmp协议所带的数据解读出来

比如oid

Name: sysUpTime系统开机时间
Oid: 1.3.6.1.2.1.1.3

Name: sysName系统名称
Oid: 1.3.6.1.2.1.1.5
Description: An administratively-assigned name for this managed node. By con
vention , this is the node's fully-qualified domain name.

 

 

Snmp Class 的阻塞方式成员函数: Get
阻塞方式的成员函数 get允许从指定 target 的代理端获取对象。调用者必须指定目标 target
以及要请求的 Pdu。
//--------[ get ]-------------------------------------------    
int  Snmp::get(  Pdu &pdu,                  // Pdu to get
                SnmpTarget &target);        // specified targe

 

pdu 与  vb

转载于:https://www.cnblogs.com/onepc/archive/2012/02/11/2346774.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值