// SnmpManagerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SnmpManager.h"
#include "SnmpManagerDlg.h"
#include "dlgset.h"
#include "dlgipin.h"
#include "dlgprint.h"
#ifdef _DEBUG
//CMemoryState oldMemState,newMemState,diffMemState;
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSnmpManagerDlg dialog
CSnmpManagerDlg::CSnmpManagerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSnmpManagerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSnmpManagerDlg)
m_sAgent = _T("");
m_sIpin = _T("");
m_sIpout = _T("");
m_sName = _T("");
m_sDesr = _T("");
m_sSysOid = _T("");
m_sSysTime = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSnmpManagerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSnmpManagerDlg)
DDX_Text(pDX, IDC_EDIT1, m_sAgent);
DDX_Text(pDX, IDC_IPIN, m_sIpin);
DDX_Text(pDX, IDC_IPOUT, m_sIpout);
DDX_Text(pDX, IDC_SYSNAME, m_sName);
DDX_Text(pDX, IDC_SYSDESR, m_sDesr);
DDX_Text(pDX, IDC_SYSOID, m_sSysOid);
DDX_Text(pDX, IDC_SYSUPTIME, m_sSysTime);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSnmpManagerDlg, CDialog)
//{{AFX_MSG_MAP(CSnmpManagerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ADDAGENT, OnAddagent)
ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
ON_MESSAGE(wMsg,OnRecv)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_END, OnEnd)
ON_BN_CLICKED(IDC_SET, OnSet)
ON_BN_CLICKED(IDC_GETNEXT, OnGetnext)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSnmpManagerDlg message handlers
BOOL CSnmpManagerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
for(int i=0;i<=9;i++)
{
m_initOid[i]=new char[100];
}
m_initOid[1]="1.3.6.1.2.1.1.1.0";
m_initOid[2]="1.3.6.1.2.1.1.2.0";
m_initOid[3]="1.3.6.1.2.1.1.3.0";
m_initOid[4]="1.3.6.1.2.1.1.5.0";
m_initOid[5]="1.3.6.1.2.1.4.3.0";
m_initOid[6]="1.3.6.1.2.1.4.10.0";
CListBox* pList=(CListBox *)GetDlgItem(IDC_LIST1);
pList->AddString("127.0.0.1");
for(i=0;i<=9;i++ )
{
m_value[i]=new smiVALUE[100];
m_sOid[i]=new char[100];
str[i]=new char[100];
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CSnmpManagerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSnmpManagerDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSnmpManagerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSnmpManagerDlg::OnAddagent()
{
UpdateData(TRUE);
CListBox* pList=(CListBox *)GetDlgItem(IDC_LIST1);
pList->AddString(m_sAgent);
}
void CSnmpManagerDlg::OnSelchangeList1()
{
//KillTimer(1);
m_Agent=new char;
CListBox* pList=(CListBox *)GetDlgItem(IDC_LIST1);
pList->GetText(pList->GetCurSel(),m_Agent);
Start();
m_preIn=m_nIpin;
SetTimer(2,1000,NULL);
}
void CSnmpManagerDlg::Start()
{ //oldMemState.Checkpoint();
//oldMemState.DumpStatistics();
if(pSnmp.sessionID==FALSE)
{
pSnmp.CreateSession(CSnmpManagerDlg::m_hWnd,wMsg);
pSnmp.sessionID=TRUE;
}
//pSnmp.Register();
pSnmp.CreateVbl(m_initOid[1],NULL);
for(int i=2;i<=6;i++)
{
pSnmp.SetVbl(m_initOid[i]);
}
pSnmp.CreatePdu(SNMP_PDU_GET,NULL,NULL,NULL);
pSnmp.Send(m_Agent,"public");
/*#ifdef _DEBUG
newMemState.Checkpoint();
if(diffMemState.Difference(oldMemState,newMemState))
{TRACE("diffrence between fire and noe\n\n");
diffMemState.DumpStatistics();
}
TRACE("new:\n\n\n\n");
newMemState.DumpStatistics();
#endif*/
}
void CSnmpManagerDlg::OnRecv()
{
int nIpin;
CString strIp;
CString strTemp;
pSnmp.Receive(m_sOid,m_value);
for(int i=1;i<=pSnmp.nCount;i++)
{
switch(m_value[i]->syntax)
{
case SNMP_SYNTAX_INT:
//case SNMP_SYNTAX_INT32:
smiINT sNumber;
sNumber=m_value[i]->value.sNumber;
nIpin=sNumber;
wsprintf(str[i],"%d",sNumber);
break;
case SNMP_SYNTAX_UINT32:
case SNMP_SYNTAX_CNTR32:
case SNMP_SYNTAX_GAUGE32:
case SNMP_SYNTAX_TIMETICKS:
smiUINT32 uNumber;
uNumber=m_value[i]->value.uNumber;
nIpin=uNumber;
wsprintf(str[i],"%d",uNumber);
break;
case SNMP_SYNTAX_CNTR64:
smiCNTR64 hNumber;
hNumber=m_value[i]->value.hNumber;
break;
case SNMP_SYNTAX_OCTETS:
case SNMP_SYNTAX_OPAQUE:
case SNMP_SYNTAX_NSAPADDR:
str[i]=(char *)m_value[i]->value.string.ptr;
break;
case SNMP_SYNTAX_IPADDR:
strIp.Format("%d",*m_value[i]->value.string.ptr);
strIp+=".";
strTemp.Format("%d",*(m_value[i]->value.string.ptr+1));
strIp+=strTemp;
strIp+=".";
strTemp.Format("%d",*(m_value[i]->value.string.ptr+2));
strIp+=strTemp;
strIp+=".";
strTemp.Format("%d",*(m_value[i]->value.string.ptr+3));
strIp+=strTemp;
strcpy(str[i],strIp);
break;
case SNMP_SYNTAX_OID:
smiOID oid;
oid=m_value[i]->value.oid;
SnmpOidToStr(&oid,30,str[i]);
//SnmpFreeDescriptor (SNMP_SYNTAX_OID, (smiLPOPAQUE)&oid);
break;
case SNMP_SYNTAX_NULL:
case SNMP_SYNTAX_NOSUCHOBJECT:
case SNMP_SYNTAX_NOSUCHINSTANCE:
case SNMP_SYNTAX_ENDOFMIBVIEW:
smiBYTE empty;
empty=m_value[i]->value.empty;
str[i]="N
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
SNMP.rar (26个子文件)
SNMP的网络安全入侵检测系统 源码
SnmpManagerDlg.h 2KB
readme.htm 223B
SnmpManager.dsp 5KB
Resource.h 1KB
DlgIpIn.cpp 943B
SnmpManager.plg 1KB
SnmpManager.cpp 2KB
Snmp.h 1KB
Snmp.cpp 6KB
RES
SnmpManager.ico 1KB
SnmpManager.rc2 403B
DlgSet.h 1KB
SnmpManager.opt 53KB
DlgSet.cpp 923B
DlgPrint.h 1KB
SnmpManager.ncb 105KB
SnmpManager.h 1KB
StdAfx.cpp 213B
SnmpManagerDlg.cpp 12KB
StdAfx.h 999B
SnmpManager.rc 7KB
SnmpManager.dsw 547B
DlgIpIn.h 1KB
DlgPrint.cpp 1KB
SnmpManager.clw 3KB
SnmpManager.aps 37KB
共 26 条
- 1
小波思基
- 粉丝: 85
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0