#include “snmp_pp.h”
#define SYSDESCR “1.3.6.1.2.1.1.1.0” // Object ID for System Descriptor
void get_system_descriptor()
{
int status; // return status
CTarget ctarget( (IpAddress) “10.4.8.5”);// SNMP++ v1 target
Vb vb( SYSDESCR); // 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
};
#define SYSDESCR “1.3.6.1.2.1.1.1.0” // Object ID for System Descriptor
void get_system_descriptor()
{
int status; // return status
CTarget ctarget( (IpAddress) “10.4.8.5”);// SNMP++ v1 target
Vb vb( SYSDESCR); // 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++库实现从远程设备获取系统描述符信息的过程。通过定义目标IP地址、OID及创建SNMP会话,完成了一次GET操作并打印出系统描述符的值。
4355

被折叠的 条评论
为什么被折叠?



