[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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM