#include <iostream> #include "snmp_pp/snmp_pp.h" using namespace std; #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)"192.168.1.111"); 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) { 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(); } }main函数,这里就不写了,直接调用这个函数就OK
原文地址:http://blog.csdn.net/zzj806683450/article/details/39054059