18,356
社区成员
发帖
与我相关
我的任务
分享
Snmp *snmp;
void GetFun(int reason, Snmp *session, Pdu &pdu, SnmpTarget &target, void *data);
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
snmp_version version = version1;
Snmp::socket_startup();
int retries=1;
unsigned long timeout=100;
u_short port= 161;
OctetStr community("public");
int status;
UdpAddress address("192.168.2.2");
CString strOid = "1.3.6.1.4.1.20353.2.1.1.85.1.0.0.23";
Oid oid(strOid);
Pdu pdu;
Vb vb;
vb.set_oid(oid);
pdu += vb;
address.set_port(port);
CTarget ctarget( address);
ctarget.set_version( version2c);
ctarget.set_retry( retries);
ctarget.set_timeout( timeout);
ctarget.set_readcommunity(community);
SnmpTarget *target;
target = &ctarget;
snmp = new Snmp(status);
status = snmp->get( pdu, *target,GetFun);
// snmp->get( pdu, *target);
// if (status == SNMP_CLASS_SUCCESS)
// {
// pdu.get_vb( vb,0);
//
// CString strval = vb.get_printable_value();
// AfxMessageBox(strval);
// }
return 0;
}
void GetFun(int reason, Snmp *session, Pdu &pdu, SnmpTarget &target, void *data)
{
Vb vb;
CString str1;
str1.Format("%d",reason);
AfxMessageBox(Snmp::error_msg(reason));
pdu.get_vb(vb,0);
CString strValue1;
strValue1 = vb.get_printable_value();
AfxMessageBox(strValue1);
}