[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