Network Monitoring & Management

Google

Wednesday, August 02, 2006

How to get Cisco running configuration using SNMP++ 3.x and VC++ MFC

The essential part of this code is SNMP++ library and TFTP server.
You can download SNMP++ form following link

http://www.agentpp.com/snmp_pp3_x/snmp_pp3_x.html

Or if you want compiled version for VC++ 6.0 send me an email

A free ware TFTP Server is here

http://tftpd32.jounin.net


//Assuming you are using MFC

//Put Snmp::socket_startup(); in your applications InitInstance

//Function parameters
//cro Read-only community
//crw Read-write community
//ciscoIP ip-address of Cisco router
//tftpServer ip-address of tftpserver
//destFile Destination file name for running configuration

//First include snmp++ header file
#include "include/snmp_pp.h"

//returns 0 if fails oterwise +ve value

int YourClass::GetConfig(CString cro, CString crw,CString ciscoIP,CString tftpServer,CString destFile)
{

int status;
Snmp* snmp = new Snmp(status,8161);

if(snmp == NULL)
{
AfxMessageBox("Snmp object creation failed !");
return(0);
}

if( status != SNMP_CLASS_SUCCESS)
{
AfxMessageBox(snmp->error_msg(status));
delete(snmp);
return(0);
}


//snmp_version
snmp_version version = version2c; // or version1

UdpAddress address(ciscoIP); // Address of your Cisco router
unsigned short port = 161; //UDP SNMP port
address.set_port(port);

//Setting Values
CTarget ctarget(address);
ctarget.set_readcommunity(cro);
ctarget.set_writecommunity(crw);
ctarget.set_retry(3);
ctarget.set_version(version);
ctarget.set_timeout(5*100);


Pdu pdu;
//pdu = new Pdu();

Vb vb;

CString oidTFTPserver;
oidTFTPserver.Format("%s%s",".1.3.6.1.4.1.9.2.1.55.",tftpServer);

vb.set_oid((Oid)oidTFTPserver);

vb.set_value(destFile);
pdu += vb;

status = snmp->set(pdu,ctarget);


if(status != SNMP_CLASS_SUCCESS)
{
CString msg_err;
AfxMessageBox(snmp->error_msg(status));
delete(snmp);
return(0);

}

return(1);

}
Deepesh Goud 11:13 PM

0 Comments:

Add a comment

Blogger