用snmp++发送get请求示例

来源:互联网 发布:软件商城开发 编辑:程序博客网 时间:2024/04/29 13:41
#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

};