//-------[ 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
2、在SNMP++库中找到查询ID的接口;
3、调用接口查询
get的方法就是要你的OID,你需要查看mib文件,找到你对应信息的OID值,这样就可以get 对应OID,然后得到返回数据,自己处理
Header files:
(这里是SNMP++的include目录的位置)
#include "C:\System Backup\D$\Snmp\Agent++\snmp++\include\snmp_pp.h"
#include "C:\System Backup\D$\Snmp\Agent++\snmp++\include\collect.h"
#include "C:\System Backup\D$\Snmp\Agent++\snmp++\include\notifyqueue.h"
Linked Libs:
snmpPP.lib deslib.lib agentpp.lib ws2_32.lib
Compiler options:
/nologo /MLd /W3 /Gm /GX /ZI /Od /I "C:\System" /I "C:\System Backup\D$\Snmp\Agent++\snmp++\include"(这里是你自己的SNMP++的include目录的位置) /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Debug/trap_recv.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ
#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
};