我的百度空间 我的51CTO空间 我的163空间

[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

posted on 2012-02-11 16:05  心若冰清  阅读(11099)  评论(1编辑  收藏  举报

导航