採用snmp協議 監控交換機(d-link)實現
//標頭檔案
// NetworkMonitorView.h : interface of the CNetworkMonitorView class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_NETWORKMONITORVIEW_H__39998FA7_50E2_4D0D_86F3_414B184C444F__INCLUDED_)
#define AFX_NETWORKMONITORVIEW_H__39998FA7_50E2_4D0D_86F3_414B184C444F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "BtnST.h"
#include "Winsnmp.h"
typedef struct _s{
int nPort ;
COleDateTimeSpan Datetime ;
CString sRoom ;
}PORTINFO;
// "房間號","上網時間","流量","單價/時","總價"} ;
typedef struct _n{
CString sRoom ;
CString sTimeOnline ;
CString sLL ;
CString sDJ ;
CString sZJ ;
}NONEVALUE;
class CNetworkMonitorView : public CFormView
{
protected: // create from serialization only
CNetworkMonitorView();
DECLARE_DYNCREATE(CNetworkMonitorView)
public:
//{{AFX_DATA(CNetworkMonitorView)
enum { IDD = IDD_NETWORKMONITOR_FORM };
CWinXPButtonST m_Port9;
CWinXPButtonST m_Port8;
CWinXPButtonST m_Port7;
CWinXPButtonST m_Port6;
CWinXPButtonST m_Port5;
CWinXPButtonST m_Port48;
CWinXPButtonST m_Port47;
CWinXPButtonST m_Port46;
CWinXPButtonST m_Port45;
CWinXPButtonST m_Port44;
CWinXPButtonST m_Port43;
CWinXPButtonST m_Port42;
CWinXPButtonST m_Port41;
CWinXPButtonST m_Port40;
CWinXPButtonST m_Port4;
CWinXPButtonST m_Port39;
CWinXPButtonST m_Port38;
CWinXPButtonST m_Port37;
CWinXPButtonST m_Port34;
CWinXPButtonST m_Port36;
CWinXPButtonST m_Port35;
CWinXPButtonST m_Port33;
CWinXPButtonST m_Port32;
CWinXPButtonST m_Port31;
CWinXPButtonST m_Port30;
CWinXPButtonST m_Port3;
CWinXPButtonST m_Port29;
CWinXPButtonST m_Port28;
CWinXPButtonST m_Port27;
CWinXPButtonST m_Port26;
CWinXPButtonST m_Port25;
CWinXPButtonST m_Port24;
CWinXPButtonST m_Port23;
CWinXPButtonST m_Port22;
CWinXPButtonST m_Port21;
CWinXPButtonST m_Port20;
CWinXPButtonST m_Port2;
CWinXPButtonST m_Port19;
CWinXPButtonST m_Port18;
CWinXPButtonST m_Port17;
CWinXPButtonST m_Port16;
CWinXPButtonST m_Port15;
CWinXPButtonST m_Port14;
CWinXPButtonST m_Port13;
CWinXPButtonST m_Port12;
CWinXPButtonST m_Port11;
CWinXPButtonST m_Port10;
CListCtrl m_ListCtrl;
CWinXPButtonST m_Port1;
//}}AFX_DATA
// Attributes
public:
CNetworkMonitorDoc* GetDocument();
CBrush m_BackgoundBrush;
void InitivalPort() ;
void ConnectionSwitch() ;
void SetValue(CString sIP1, CString sIP2, CString sDJ, CString sFreq) ;
protected:
static DWORD WINAPI ThreadProc(LPVOID lpParam) ;
static DWORD WINAPI ThreadProc2(LPVOID lpParam) ;
void UpdateRow(int nPort, CString sRomm, COleDateTimeSpan *pOleDateTime, int nLL ) ;
BOOL Computer(CString sRoom, int nPort, PORTINFO **pPortInfo) ;
void SaveNoneValue(CString sRomm, COleDateTimeSpan *pOleDateTime, int nLL) ;
void LoadNoneValue() ;
void ShowNoneValue() ;
private:
BOOL m_b1 ;
BOOL m_b2 ;
int m_IndexItem ;
static HANDLE m_ThreadHandle1 ;
static HSNMP_ENTITY m_hsrcAgent1;
static HSNMP_CONTEXT m_hContext1;
static HANDLE m_ThreadHandle2 ;
static HSNMP_ENTITY m_hsrcAgent2;
static HSNMP_CONTEXT m_hContext2;
static BOOL bIsFi ;
static BOOL bIsFi2 ;
int nListItemIndex ;
float m_fDJ ;
BOOL m_bIsFirst ;
BOOL m_bISFirst2 ;
BOOL m_bFerq;
CString m_sDJ ;
CString m_sIP1;
CString m_sIP2 ;
CString m_sFreq ;
int m_nFreq ;
CString m_sRoom ;
int m_nFerq ;
CArray<PORTINFO* ,PORTINFO*> m_PortInfo ;
CArray<NONEVALUE* , NONEVALUE*> m_NoneValue ;
BOOL m_bIsUpdate ;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CNetworkMonitorView)
public:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual void OnInitialUpdate(); // called first time after construct
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL
afx_msg void OnMessageBlock(UINT nID);
// Implementation
public:
virtual ~CNetworkMonitorView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CNetworkMonitorView)
afx_msg void OnButtonPort19();
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnDestroy();
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnRclickList1(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnMenuJz();
//}}AFX_MSG
afx_msg void OnSanComplie(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
};
#ifndef _DEBUG // debug version in NetworkMonitorView.cpp
inline CNetworkMonitorDoc* CNetworkMonitorView::GetDocument()
{ return (CNetworkMonitorDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_NETWORKMONITORVIEW_H__39998FA7_50E2_4D0D_86F3_414B184C444F__INCLUDED_)
// 實現cpp
// NetworkMonitorView.cpp : implementation of the CNetworkMonitorView class
//
#include "stdafx.h"
#include "NetworkMonitor.h"
#include "NetworkMonitorDoc.h"
#include "NetworkMonitorView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CNetworkMonitorView
#define WM_SCANCOMPLIE WM_USER+203
static LPCTSTR g_sIREventName = "NETMONITORZBJ" ;
static LPCTSTR g_sIREventName2 = "NETMONITORZBJ2" ;
CString g_sValue1 ;
smiOID g_Oid ;
char g_buffer[40] ;
int g_Counter = 0 ;
int g_TimeCounter = 0 ;
CString g_sValue2 ;
smiOID g_Oid2 ;
char g_buffer2[40] ;
int g_Counter2 = 0 ;
int g_TimeCounter2 = 0 ;
smiINT PortFlag[28] ;
smiINT PortTime[28] ;
smiINT PortFirstLL[28] ;
smiINT PortFlag2[28] ;
smiINT PortTime2[28] ;
smiINT PortFirstLL2[28] ;
SNMPAPI_STATUS CALLBACK mycall(
HSNMP_SESSION hSession, // handle to the WinSNMP session
HWND hWnd, // handle to the notification window
UINT wMsg, // window notification message number
WPARAM wParam, // type of notification
LPARAM lParam, // request identifier of PDU
LPVOID lpClientData // optional application-defined data
) ;
SNMPAPI_STATUS CALLBACK mycall2(
HSNMP_SESSION hSession, // handle to the WinSNMP session
HWND hWnd, // handle to the notification window
UINT wMsg, // window notification message number
WPARAM wParam, // type of notification
LPARAM lParam, // request identifier of PDU
LPVOID lpClientData // optional application-defined data
) ;
char *OIDBuf[] = {
"1.3.6.1.2.1.2.2.1.5.1",
"1.3.6.1.2.1.2.2.1.5.2",
"1.3.6.1.2.1.2.2.1.5.3",
"1.3.6.1.2.1.2.2.1.5.4",
"1.3.6.1.2.1.2.2.1.5.5",
"1.3.6.1.2.1.2.2.1.5.6",
"1.3.6.1.2.1.2.2.1.5.7",
"1.3.6.1.2.1.2.2.1.5.8",
"1.3.6.1.2.1.2.2.1.5.9",
"1.3.6.1.2.1.2.2.1.5.10",
"1.3.6.1.2.1.2.2.1.5.11",
"1.3.6.1.2.1.2.2.1.5.12",
"1.3.6.1.2.1.2.2.1.5.13",
"1.3.6.1.2.1.2.2.1.5.14",
"1.3.6.1.2.1.2.2.1.5.15",
"1.3.6.1.2.1.2.2.1.5.16",
"1.3.6.1.2.1.2.2.1.5.17",
"1.3.6.1.2.1.2.2.1.5.18",
"1.3.6.1.2.1.2.2.1.5.19",
"1.3.6.1.2.1.2.2.1.5.20",
"1.3.6.1.2.1.2.2.1.5.21",
"1.3.6.1.2.1.2.2.1.5.22",
"1.3.6.1.2.1.2.2.1.5.23",
"1.3.6.1.2.1.2.2.1.5.24",
"1.3.6.1.2.1.2.2.1.5.25",
"1.3.6.1.2.1.2.2.1.5.26",
"1.3.6.1.2.1.2.2.1.5.27",
"1.3.6.1.2.1.2.2.1.5.28"
} ;
char *OIDTime[] = {
"1.3.6.1.2.1.2.2.1.10.1",
"1.3.6.1.2.1.2.2.1.10.2",
"1.3.6.1.2.1.2.2.1.10.3",
"1.3.6.1.2.1.2.2.1.10.4",
"1.3.6.1.2.1.2.2.1.10.5",
"1.3.6.1.2.1.2.2.1.10.6",
"1.3.6.1.2.1.2.2.1.10.7",
"1.3.6.1.2.1.2.2.1.10.8",
"1.3.6.1.2.1.2.2.1.10.9",
"1.3.6.1.2.1.2.2.1.10.10",
"1.3.6.1.2.1.2.2.1.10.11",
"1.3.6.1.2.1.2.2.1.10.12",
"1.3.6.1.2.1.2.2.1.10.13",
"1.3.6.1.2.1.2.2.1.10.14",
"1.3.6.1.2.1.2.2.1.10.15",
"1.3.6.1.2.1.2.2.1.10.16",
"1.3.6.1.2.1.2.2.1.10.17",
"1.3.6.1.2.1.2.2.1.10.18",
"1.3.6.1.2.1.2.2.1.10.19",
"1.3.6.1.2.1.2.2.1.10.20",
"1.3.6.1.2.1.2.2.1.10.21",
"1.3.6.1.2.1.2.2.1.10.22",
"1.3.6.1.2.1.2.2.1.10.23",
"1.3.6.1.2.1.2.2.1.10.24",
"1.3.6.1.2.1.2.2.1.10.25",
"1.3.6.1.2.1.2.2.1.10.26",
"1.3.6.1.2.1.2.2.1.10.27",
"1.3.6.1.2.1.2.2.1.10.28"
} ;
IMPLEMENT_DYNCREATE(CNetworkMonitorView, CFormView)
HANDLE CNetworkMonitorView::m_ThreadHandle1 ;
HSNMP_ENTITY CNetworkMonitorView::m_hsrcAgent1 ;
HSNMP_CONTEXT CNetworkMonitorView::m_hContext1 ;
HANDLE CNetworkMonitorView::m_ThreadHandle2 ;
HSNMP_ENTITY CNetworkMonitorView::m_hsrcAgent2 ;
HSNMP_CONTEXT CNetworkMonitorView::m_hContext2 ;
BOOL CNetworkMonitorView::bIsFi = FALSE ;
BOOL CNetworkMonitorView::bIsFi2 = FALSE ;
HSNMP_SESSION m_hSession1 ;
HSNMP_SESSION m_hSession2 ;
HANDLE m_GetEvent1 ;
HANDLE m_GetEvent2 ;
BEGIN_MESSAGE_MAP(CNetworkMonitorView, CFormView)
ON_CONTROL_RANGE(BN_CLICKED,IDC_BUTTON_PORT1,IDC_BUTTON_PORT23,OnMessageBlock)
//{{AFX_MSG_MAP(CNetworkMonitorView)
ON_BN_CLICKED(IDC_BUTTON_PORT19, OnButtonPort19)
ON_WM_CTLCOLOR()
ON_WM_SIZE()
ON_WM_DESTROY()
ON_WM_TIMER()
ON_NOTIFY(NM_RCLICK, IDC_LIST1, OnRclickList1)
ON_COMMAND(ID_MENU_JZ, OnMenuJz)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
ON_MESSAGE(WM_SCANCOMPLIE,OnSanComplie)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNetworkMonitorView construction/destruction
CNetworkMonitorView::CNetworkMonitorView()
: CFormView(CNetworkMonitorView::IDD)
{
//{{AFX_DATA_INIT(CNetworkMonitorView)
//}}AFX_DATA_INIT
// TODO: add construction code here
m_BackgoundBrush.CreateSolidBrush(RGB(32,47,75)) ;
nListItemIndex = 0 ;
m_sDJ = "1.5";
m_sIP1 = "192.168.0.1";
m_sIP2 = "192.168.0.2";
m_nFerq = 1 ;
m_bIsUpdate = FALSE ;
m_bFerq = FALSE ;
m_b1 = FALSE;
m_b2 = FALSE ;
m_nFreq = 1 ;
}
CNetworkMonitorView::~CNetworkMonitorView()
{
}
void CNetworkMonitorView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNetworkMonitorView)
DDX_Control(pDX, IDC_BUTTON_PORT9, m_Port9);
DDX_Control(pDX, IDC_BUTTON_PORT8, m_Port8);
DDX_Control(pDX, IDC_BUTTON_PORT7, m_Port7);
DDX_Control(pDX, IDC_BUTTON_PORT6, m_Port6);
DDX_Control(pDX, IDC_BUTTON_PORT5, m_Port5);
DDX_Control(pDX, IDC_BUTTON_PORT48, m_Port48);
DDX_Control(pDX, IDC_BUTTON_PORT47, m_Port47);
DDX_Control(pDX, IDC_BUTTON_PORT46, m_Port46);
DDX_Control(pDX, IDC_BUTTON_PORT45, m_Port45);
DDX_Control(pDX, IDC_BUTTON_PORT44, m_Port44);
DDX_Control(pDX, IDC_BUTTON_PORT43, m_Port43);
DDX_Control(pDX, IDC_BUTTON_PORT42, m_Port42);
DDX_Control(pDX, IDC_BUTTON_PORT41, m_Port41);
DDX_Control(pDX, IDC_BUTTON_PORT40, m_Port40);
DDX_Control(pDX, IDC_BUTTON_PORT4, m_Port4);
DDX_Control(pDX, IDC_BUTTON_PORT39, m_Port39);
DDX_Control(pDX, IDC_BUTTON_PORT38, m_Port38);
DDX_Control(pDX, IDC_BUTTON_PORT37, m_Port37);
DDX_Control(pDX, IDC_BUTTON_PORT34, m_Port34);
DDX_Control(pDX, IDC_BUTTON_PORT36, m_Port36);
DDX_Control(pDX, IDC_BUTTON_PORT35, m_Port35);
DDX_Control(pDX, IDC_BUTTON_PORT33, m_Port33);
DDX_Control(pDX, IDC_BUTTON_PORT32, m_Port32);
DDX_Control(pDX, IDC_BUTTON_PORT31, m_Port31);
DDX_Control(pDX, IDC_BUTTON_PORT30, m_Port30);
DDX_Control(pDX, IDC_BUTTON_PORT3, m_Port3);
DDX_Control(pDX, IDC_BUTTON_PORT29, m_Port29);
DDX_Control(pDX, IDC_BUTTON_PORT28, m_Port28);
DDX_Control(pDX, IDC_BUTTON_PORT27, m_Port27);
DDX_Control(pDX, IDC_BUTTON_PORT26, m_Port26);
DDX_Control(pDX, IDC_BUTTON_PORT25, m_Port25);
DDX_Control(pDX, IDC_BUTTON_PORT24, m_Port24);
DDX_Control(pDX, IDC_BUTTON_PORT23, m_Port23);
DDX_Control(pDX, IDC_BUTTON_PORT22, m_Port22);
DDX_Control(pDX, IDC_BUTTON_PORT21, m_Port21);
DDX_Control(pDX, IDC_BUTTON_PORT20, m_Port20);
DDX_Control(pDX, IDC_BUTTON_PORT2, m_Port2);
DDX_Control(pDX, IDC_BUTTON_PORT19, m_Port19);
DDX_Control(pDX, IDC_BUTTON_PORT18, m_Port18);
DDX_Control(pDX, IDC_BUTTON_PORT17, m_Port17);
DDX_Control(pDX, IDC_BUTTON_PORT16, m_Port16);
DDX_Control(pDX, IDC_BUTTON_PORT15, m_Port15);
DDX_Control(pDX, IDC_BUTTON_PORT14, m_Port14);
DDX_Control(pDX, IDC_BUTTON_PORT13, m_Port13);
DDX_Control(pDX, IDC_BUTTON_PORT12, m_Port12);
DDX_Control(pDX, IDC_BUTTON_PORT11, m_Port11);
DDX_Control(pDX, IDC_BUTTON_PORT10, m_Port10);
DDX_Control(pDX, IDC_LIST1, m_ListCtrl);
DDX_Control(pDX, IDC_BUTTON_PORT1, m_Port1);
//}}AFX_DATA_MAP
}
BOOL CNetworkMonitorView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CNetworkMonitorView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
InitivalPort() ;
smiLPUINT32 m_nMajorVersion , m_nMinorVersion , m_nLevel , m_nTranslateMode , m_nRetransmitMode ;
if (SNMPAPI_SUCCESS == SnmpStartup((smiLPUINT32)&m_nMajorVersion, (smiLPUINT32)&m_nMinorVersion, /
(smiLPUINT32)&m_nLevel, (smiLPUINT32)&m_nTranslateMode, (smiLPUINT32)&m_nRetransmitMode))
{
}
if(SnmpSetTranslateMode(SNMPAPI_UNTRANSLATED_V1)!=SNMPAPI_SUCCESS)
AfxMessageBox("SetTranslateMode failure");
if(SnmpSetRetransmitMode(SNMPAPI_ON)!=SNMPAPI_SUCCESS)
AfxMessageBox("SetRetransmitMode failure");
m_hSession1 = SnmpCreateSession(NULL, 0, mycall, this);
//SNMPAPI_STATUS trasMode=SnmpSetTranslateMode(SNMPAPI_UNTRANSLATED_V1); //設定傳輸模式
m_hsrcAgent1 = SnmpStrToEntity(m_hSession1, m_sIP1);
char * comm="public"; //團體字不便透露,用public替代
smiOCTETS community;
community.len=6;
community.ptr=(unsigned char *)comm;
m_hContext1 = SnmpStrToContext(m_hSession1, &community);
m_hSession2 = SnmpCreateSession(NULL, 0, mycall2, this);
m_hsrcAgent2 = SnmpStrToEntity(m_hSession2, m_sIP2);
m_hContext2 = SnmpStrToContext(m_hSession2, &community);
memset(&PortFlag, 0, sizeof(PortFlag)) ;
memset(&PortTime, 0, sizeof(PortTime)) ;
memset(&PortFirstLL, 0, sizeof(PortFirstLL)) ;
memset(&PortFlag2, 0, sizeof(PortFlag2)) ;
memset(&PortTime2, 0, sizeof(PortTime2)) ;
memset(&PortFirstLL2, 0, sizeof(PortFirstLL2)) ;
ConnectionSwitch() ;
m_bIsFirst = TRUE ;
m_bISFirst2 = TRUE ;
m_GetEvent1 = ::CreateEvent(NULL,TRUE,TRUE,g_sIREventName) ;
m_GetEvent2 = ::CreateEvent(NULL,TRUE,TRUE,g_sIREventName2) ;
SetTimer(100,1000*60*m_nFreq, NULL) ;
LoadNoneValue() ;
ShowNoneValue() ;
}
void CNetworkMonitorView::LoadNoneValue()
{
char inBuf[80];
CString str ;
for(int i = 1 ; i <= ALL_PORT ; i++ )
{
str.Format("%d", i) ;
memset(inBuf,0,sizeof(inBuf)) ;
if(GetPrivateProfileString ("nonevalue", "room"+str, NULL,inBuf,80,".//config.ini") >=1)
{
NONEVALUE * pNoneValue = new NONEVALUE ;
pNoneValue->sRoom = inBuf ;
GetPrivateProfileString ("nonevalue", "Time"+str, NULL,inBuf,80,".//config.ini") ;
pNoneValue->sTimeOnline = inBuf ;
GetPrivateProfileString ("nonevalue", "LL"+str, NULL,inBuf,80,".//config.ini") ;
pNoneValue->sLL = inBuf ;
GetPrivateProfileString ("nonevalue", "DJ"+str, NULL,inBuf,80,".//config.ini");
pNoneValue->sDJ = inBuf ;
GetPrivateProfileString ("nonevalue", "ZJ"+str, NULL,inBuf,80,".//config.ini");
pNoneValue->sZJ = inBuf ;
m_NoneValue.Add(pNoneValue) ;
}
}
}
void CNetworkMonitorView::InitivalPort()
{
for( UINT ID = IDC_BUTTON_PORT1 ; ID <= IDC_BUTTON_PORT24 ; ID++)
{
CWinXPButtonST *pWinXpButton = (CWinXPButtonST*)GetDlgItem(ID) ;
pWinXpButton->SetIcon(IDI_ICON1) ;
pWinXpButton->SetID(ID-(IDC_BUTTON_PORT1-1)) ;
}
for( ID = IDC_BUTTON_PORT25 ; ID <= IDC_BUTTON_PORT48 ; ID++)
{
CWinXPButtonST *pWinXpButton = (CWinXPButtonST*)GetDlgItem(ID) ;
pWinXpButton->SetIcon(IDI_ICON1) ;
pWinXpButton->SetID(ID-(IDC_BUTTON_PORT25-1)+24) ;
}
DWORD dwLStyle = LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT;
m_ListCtrl.SetExtendedStyle(dwLStyle);
LV_COLUMN m_Column;
m_Column.mask = LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;
m_Column.fmt = LVCFMT_LEFT;
int iFieldCx[5] = {150,250 ,100,250 ,250};
char*pszArray[5] = {"房間號","上網時間","流量","單價/時","總價"} ;
for(int i = 0;i<5;i++)
{
m_Column.pszText = pszArray[i] ;
m_Column.cx = iFieldCx[i];
m_Column.iSubItem = i;
m_ListCtrl.InsertColumn(i,&m_Column);
}
char inBuf[80];
memset(inBuf,0,sizeof(inBuf)) ;
GetPrivateProfileString ("set", "ip1", "192.168.0.1",inBuf,80,".//config.ini");
m_sIP1 = inBuf ;
memset(inBuf,0,sizeof(inBuf)) ;
GetPrivateProfileString ("set", "ip2", "192.168.0.2",inBuf,80,".//config.ini");
m_sIP2 = inBuf ;
memset(inBuf,0,sizeof(inBuf)) ;
GetPrivateProfileString ("set", "DJ", "1.5",inBuf,80,".//config.ini");
m_sDJ = inBuf ;
m_fDJ = atof(m_sDJ) ;
memset(inBuf,0,sizeof(inBuf)) ;
GetPrivateProfileString ("set", "freq", "1",inBuf,80,".//config.ini");
m_sFreq = inBuf ;
m_nFreq = atoi(m_sFreq) ;
}
/////////////////////////////////////////////////////////////////////////////
// CNetworkMonitorView printing
BOOL CNetworkMonitorView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CNetworkMonitorView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CNetworkMonitorView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CNetworkMonitorView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CNetworkMonitorView diagnostics
#ifdef _DEBUG
void CNetworkMonitorView::AssertValid() const
{
CFormView::AssertValid();
}
void CNetworkMonitorView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CNetworkMonitorDoc* CNetworkMonitorView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CNetworkMonitorDoc)));
return (CNetworkMonitorDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CNetworkMonitorView message handlers
void CNetworkMonitorView::OnButtonPort19()
{
// TODO: Add your control notification handler code here
}
HBRUSH CNetworkMonitorView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(pWnd == this)
return m_BackgoundBrush ;
if(nCtlColor== CTLCOLOR_STATIC)
{
pDC->SetBkMode(TRANSPARENT) ;
//pDC->SetBkColor(RGB(20,200,20)) ;
pDC->SetTextColor(RGB(255,255,255)) ;
HBRUSH hBrush = (HBRUSH)::GetStockObject(HOLLOW_BRUSH) ;
return hBrush ;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CNetworkMonitorView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CRect rect ;
GetClientRect(&rect) ;
if(m_ListCtrl)
m_ListCtrl.SetWindowPos(&CWnd::wndTop,rect.left,rect.bottom - 200,rect.Width(),200,SWP_NOOWNERZORDER) ;
}
// 1052 ~ 1111
void CNetworkMonitorView::OnMessageBlock(UINT nID)
{
// TODO: Add your control notification handler code here
//CWinXPButtonST* pWnd;
UINT nBaseID;
//LV_COLUMN m_Column;
nBaseID = IDC_BUTTON_PORT1;
if((nID>=IDC_BUTTON_PORT1) && (nID<=IDC_BUTTON_PORT23))
{
}
}
SNMPAPI_STATUS CALLBACK mycall(
HSNMP_SESSION hSession, // handle to the WinSNMP session
HWND hWnd, // handle to the notification window
UINT wMsg, // window notification message number
WPARAM wParam, // type of notification
LPARAM lParam, // request identifier of PDU
LPVOID lpClientData // optional application-defined data
)
{
HSNMP_ENTITY recsrcEntity;
HSNMP_ENTITY recdisEntity;
HSNMP_CONTEXT reccontext;
HSNMP_PDU recPDU;
SNMPAPI_STATUS recStat=SnmpRecvMsg(hSession,&recsrcEntity,&recdisEntity,&reccontext,&recPDU); //接受訊息
if(SNMPAPI_FAILURE == recStat )
{
SNMPAPI_STATUS st = SnmpGetLastError(hSession) ;
return 1L;
}
smiINT PduType, ErrorStatus, ErrorIndex;
HSNMP_VBL recVBL;
smiINT32 nReqId;
smiVALUE sVal;
smiOID sOid;
SNMPAPI_STATUS GetPDUstat=SnmpGetPduData(recPDU,&PduType,&nReqId,&ErrorStatus,/
&ErrorIndex,&recVBL); //提取PDU
if( SNMPAPI_FAILURE == GetPDUstat)
{
return 1L;
}
smiINT Val ;
char cTmp[1024] ;
if (PduType == SNMP_PDU_RESPONSE)
{
SNMPAPI_STATUS Stat = SnmpGetVb(recVBL, 1, &sOid, &sVal);
memcpy(&g_Oid,&sOid,sizeof(smiOID));
SnmpOidToStr(&sOid, 40 ,g_buffer) ;
switch (sVal.syntax) {
case SNMP_SYNTAX_INT32:
case SNMP_SYNTAX_UINT32:
case SNMP_SYNTAX_CNTR32:
case SNMP_SYNTAX_GAUGE32:
Val = sVal.value.sNumber;
if (g_Counter < 28)
{
if(strcmp(OIDBuf[g_Counter], g_buffer) == 0)
{
PortFlag[g_Counter] = Val ;
g_Counter++ ;
}
}
else if (g_TimeCounter < 28)
{
if(strcmp(OIDTime[g_TimeCounter], g_buffer) == 0)
{
PortTime[g_TimeCounter] = Val ;
g_TimeCounter++ ;
}
}
break;
case SNMP_SYNTAX_TIMETICKS:
//
// days = tt / 8640000;
// tt %= 8640000;
//
// // hours
// hours = tt / 360000;
// tt %= 360000;
//
// // minutes
// minutes = tt / 6000;
// tt %= 6000;
//
// seconds = tt / 100;
// tt %= 100;
//
// hseconds = tt;
Val = sVal.value.sNumber;
break ;
case SNMP_SYNTAX_CNTR64:
Val = sVal.value.hNumber.hipart << 32;
Val += sVal.value.hNumber.lopart;
break;
case SNMP_SYNTAX_OCTETS:
case SNMP_SYNTAX_BITS:
case SNMP_SYNTAX_OPAQUE:
{
memset(cTmp, 0, 1024);
for (int i=0; i<(int)sVal.value.string.len; i++)
cTmp[i] = sVal.value.string.ptr[i];
g_sValue1.Format("String: %s",cTmp);
}
break;
case SNMP_SYNTAX_IPADDR:
case SNMP_SYNTAX_NSAPADDR:
{
memset(cTmp, 0, 1024);
sprintf(cTmp, "%d.%d.%d.%d",
sVal.value.string.ptr[0],
sVal.value.string.ptr[1],
sVal.value.string.ptr[2],
sVal.value.string.ptr[3]);
//Re.Format("String: %s",cTmp);
}
break;
case SNMP_SYNTAX_OID:
{
memset(cTmp, 0, 1024);
for (int i=0; i<(int)sVal.value.string.len; i++)
cTmp[i] = sVal.value.string.ptr[i];
g_sValue1.Format("String: %s",cTmp);
}
break;
default:
break;
}
}
SetEvent(m_GetEvent1) ;
return 1L;
}
SNMPAPI_STATUS CALLBACK mycall2(
HSNMP_SESSION hSession, // handle to the WinSNMP session
HWND hWnd, // handle to the notification window
UINT wMsg, // window notification message number
WPARAM wParam, // type of notification
LPARAM lParam, // request identifier of PDU
LPVOID lpClientData // optional application-defined data
)
{
HSNMP_ENTITY recsrcEntity;
HSNMP_ENTITY recdisEntity;
HSNMP_CONTEXT reccontext;
HSNMP_PDU recPDU;
SNMPAPI_STATUS recStat=SnmpRecvMsg(hSession,&recsrcEntity,&recdisEntity,&reccontext,&recPDU); //接受訊息
if(SNMPAPI_FAILURE == recStat )
{
SNMPAPI_STATUS st = SnmpGetLastError(hSession) ;
return 1L;
}
smiINT PduType, ErrorStatus, ErrorIndex;
HSNMP_VBL recVBL;
smiINT32 nReqId;
smiVALUE sVal;
smiOID sOid;
SNMPAPI_STATUS GetPDUstat=SnmpGetPduData(recPDU,&PduType,&nReqId,&ErrorStatus,/
&ErrorIndex,&recVBL); //提取PDU
if( SNMPAPI_FAILURE == GetPDUstat)
{
return 1L;
}
smiINT Val ;
if (PduType == SNMP_PDU_RESPONSE)
{
SNMPAPI_STATUS Stat = SnmpGetVb(recVBL, 1, &sOid, &sVal);
memcpy(&g_Oid,&sOid,sizeof(smiOID));
SnmpOidToStr(&sOid, 40 ,g_buffer2) ;
switch (sVal.syntax) {
case SNMP_SYNTAX_INT32:
case SNMP_SYNTAX_UINT32:
case SNMP_SYNTAX_CNTR32:
case SNMP_SYNTAX_GAUGE32:
Val = sVal.value.sNumber;
if (g_Counter2 < 28)
{
if(strcmp(OIDBuf[g_Counter2], g_buffer2) == 0)
{
PortFlag2[g_Counter2] = Val ;
g_Counter2++ ;
}
}
else if (g_TimeCounter2 < 28)
{
if(strcmp(OIDTime[g_TimeCounter2], g_buffer2) == 0)
{
PortTime2[g_TimeCounter2] = Val ;
g_TimeCounter2++ ;
}
}
break;
case SNMP_SYNTAX_TIMETICKS:
case SNMP_SYNTAX_CNTR64:
case SNMP_SYNTAX_OCTETS:
case SNMP_SYNTAX_BITS:
case SNMP_SYNTAX_OPAQUE:
case SNMP_SYNTAX_IPADDR:
case SNMP_SYNTAX_NSAPADDR:
break;
case SNMP_SYNTAX_OID:
break;
default:
break;
}
}
SetEvent(m_GetEvent2) ;
return 1L;
}
void CNetworkMonitorView::ConnectionSwitch()
{
//建立oid
m_bFerq = FALSE ;
m_b1 = FALSE;
m_b2 = FALSE ;
m_ThreadHandle1 = CreateThread(NULL, 0, ThreadProc , reinterpret_cast<LPVOID>(this) , 0 , NULL ) ;
m_ThreadHandle2 = CreateThread(NULL, 0, ThreadProc2 , reinterpret_cast<LPVOID>(this) , 0 , NULL ) ;
}
DWORD WINAPI CNetworkMonitorView::ThreadProc(LPVOID lpParam)
{
CNetworkMonitorView* pImageShow = reinterpret_cast<CNetworkMonitorView *>(lpParam) ;
//ASSERT(pImageShow) ;
smiOID myOid;
HSNMP_VBL hVbl ;
HSNMP_PDU m_hpdu ;
static int nTempCounter = 0 ;
nTempCounter = 0 ;
g_Counter = 0 ;
memset(&PortFlag, 0, sizeof(PortFlag)) ;
bIsFi = FALSE ;
while (!bIsFi)
{
::WaitForSingleObject(m_GetEvent1,INFINITE);
ResetEvent(m_GetEvent1) ;
if (g_Counter == 0 )
{
LPCSTR pOid="1.3.6.1.2.1.2.2.1.4.604";
SNMPAPI_STATUS oidstatu = SnmpStrToOid(pOid,&myOid);
}
else
{
if(strcmp("1.3.6.1.2.1.2.2.1.5.604" ,g_buffer ) == 0 )
{
bIsFi = TRUE ;
continue ;
}
LPCSTR pOid= g_buffer;
SNMPAPI_STATUS oidstatu = SnmpStrToOid(pOid,&myOid);
}
hVbl = SnmpCreateVbl(m_hSession1, &myOid, NULL);
m_hpdu=SnmpCreatePdu(m_hSession1,SNMP_PDU_GETNEXT,NULL,NULL,NULL,hVbl); //建立PDU
SnmpSendMsg(m_hSession1, NULL, m_hsrcAgent1, m_hContext1, m_hpdu) ;
SnmpFreePdu(m_hpdu) ;
SnmpFreeVbl(hVbl) ;
nTempCounter++ ;
if (nTempCounter > 5 )
{
if (g_Counter == 0 )
{
bIsFi = TRUE ;
}
}
}
// 傳送時間timetick
bIsFi = FALSE ;
nTempCounter = 0 ;
g_TimeCounter = 0 ;
SetEvent(m_GetEvent1) ;
while (!bIsFi)
{
::WaitForSingleObject(m_GetEvent1,INFINITE);
ResetEvent(m_GetEvent1) ;
if (g_TimeCounter == 0 )
{
LPCSTR pOid="1.3.6.1.2.1.2.2.1.9.604";
SNMPAPI_STATUS oidstatu = SnmpStrToOid(pOid,&myOid);
}
else
{
if(strcmp("1.3.6.1.2.1.2.2.1.10.604" ,g_buffer ) == 0 )
{
bIsFi = TRUE ;
continue ;
}
LPCSTR pOid= g_buffer;
SNMPAPI_STATUS oidstatu = SnmpStrToOid(pOid,&myOid);
}
hVbl = SnmpCreateVbl(m_hSession1, &myOid, NULL);
m_hpdu=SnmpCreatePdu(m_hSession1,SNMP_PDU_GETNEXT,NULL,NULL,NULL,hVbl); //建立PDU
SnmpSendMsg(m_hSession1, NULL, m_hsrcAgent1, m_hContext1, m_hpdu) ;
SnmpFreePdu(m_hpdu) ;
SnmpFreeVbl(hVbl) ;
nTempCounter++ ;
if (nTempCounter > 5 )
{
if (g_TimeCounter == 0 )
{
bIsFi = TRUE ;
}
}
}
nTempCounter = 0 ;
::PostMessage(pImageShow->GetSafeHwnd(), WM_SCANCOMPLIE,0,0) ;
return 0l ;
}
DWORD WINAPI CNetworkMonitorView::ThreadProc2(LPVOID lpParam)
{
CNetworkMonitorView* pImageShow = reinterpret_cast<CNetworkMonitorView *>(lpParam) ;
//ASSERT(pImageShow) ;
smiOID myOid;
HSNMP_VBL hVbl ;
HSNMP_PDU m_hpdu ;
static int nTempCounter = 0 ;
nTempCounter = 0 ;
g_Counter2 = 0 ;
memset(&PortFlag2, 0, sizeof(PortFlag2)) ;
bIsFi2 = FALSE ;
while (!bIsFi2)
{
::WaitForSingleObject(m_GetEvent2,INFINITE);
ResetEvent(m_GetEvent2) ;
if (g_Counter2 == 0 )
{
LPCSTR pOid="1.3.6.1.2.1.2.2.1.4.604";
SNMPAPI_STATUS oidstatu = SnmpStrToOid(pOid,&myOid);
}
else
{
if(strcmp("1.3.6.1.2.1.2.2.1.5.604" ,g_buffer2 ) == 0 )
{
bIsFi2 = TRUE ;
continue ;
}
LPCSTR pOid= g_buffer2;
SNMPAPI_STATUS oidstatu = SnmpStrToOid(pOid,&myOid);
}
hVbl = SnmpCreateVbl(m_hSession2, &myOid, NULL);
m_hpdu=SnmpCreatePdu(m_hSession2,SNMP_PDU_GETNEXT,NULL,NULL,NULL,hVbl); //建立PDU
SnmpSendMsg(m_hSession2, NULL, m_hsrcAgent2, m_hContext2, m_hpdu) ;
SnmpFreePdu(m_hpdu) ;
SnmpFreeVbl(hVbl) ;
nTempCounter++ ;
if (nTempCounter > 5 )
{
if (g_Counter2 == 0 )
{
bIsFi = TRUE ;
}
}
}
// 傳送時間timetick
bIsFi2 = FALSE ;
nTempCounter = 0 ;
g_TimeCounter2 = 0 ;
SetEvent(m_GetEvent2) ;
while (!bIsFi2)
{
::WaitForSingleObject(m_GetEvent2,INFINITE);
ResetEvent(m_GetEvent2) ;
if (g_TimeCounter2 == 0 )
{
LPCSTR pOid="1.3.6.1.2.1.2.2.1.9.604";
SNMPAPI_STATUS oidstatu = SnmpStrToOid(pOid,&myOid);
}
else
{
if(strcmp("1.3.6.1.2.1.2.2.1.10.604" ,g_buffer2 ) == 0 )
{
bIsFi2 = TRUE ;
continue ;
}
LPCSTR pOid= g_buffer2;
SNMPAPI_STATUS oidstatu = SnmpStrToOid(pOid,&myOid);
}
hVbl = SnmpCreateVbl(m_hSession2, &myOid, NULL);
m_hpdu=SnmpCreatePdu(m_hSession2,SNMP_PDU_GETNEXT,NULL,NULL,NULL,hVbl); //建立PDU
SnmpSendMsg(m_hSession2, NULL, m_hsrcAgent2, m_hContext2, m_hpdu) ;
SnmpFreePdu(m_hpdu) ;
SnmpFreeVbl(hVbl) ;
nTempCounter++ ;
if (nTempCounter > 5 )
{
if (g_TimeCounter2 == 0 )
{
bIsFi = TRUE ;
}
}
}
nTempCounter = 0 ;
::PostMessage(pImageShow->GetSafeHwnd(), WM_SCANCOMPLIE,0,1) ;
return 0l ;
}
void CNetworkMonitorView::OnSanComplie(WPARAM wParam, LPARAM lParam)
{
int nCounter = 0 ;
PORTINFO *pPortInfo = NULL ;
if (!m_bFerq)
{
if (lParam == 0)
m_b2 = TRUE ;
else
m_b1 = TRUE ;
m_bFerq = TRUE ;
}
if (lParam == 0)
{
if(m_bIsFirst)
{
m_bIsFirst = FALSE ;
memcpy(&PortFirstLL, &PortTime, sizeof(PortTime)) ;
}
for( UINT ID = IDC_BUTTON_PORT1 ; ID <= IDC_BUTTON_PORT24 ; ID++)
{
CWinXPButtonST *pWinXpButton = (CWinXPButtonST*)GetDlgItem(ID) ;
if (PortFlag[nCounter] == 100000000)
{
pWinXpButton->SetIcon(IDI_ICON3) ;
Computer(pWinXpButton->GetText(),nCounter, &pPortInfo) ;
//UpdateRow(nCounter, pWinXpButton->GetText(),&pPortInfo->Datetime,PortTime[nCounter] - PortFirstLL[nCounter]) ;
}
else
{
pWinXpButton->SetIcon(IDI_ICON1) ;
}
nCounter++ ;
}
if(m_b1)
ShowNoneValue() ;
}
else if(lParam == 1)
{
if(m_bISFirst2)
{
m_bISFirst2 = FALSE ;
memcpy(&PortFirstLL2, &PortTime2, sizeof(PortTime2)) ;
}
for( UINT ID = IDC_BUTTON_PORT25 ; ID <= IDC_BUTTON_PORT48 ; ID++)
{
CWinXPButtonST *pWinXpButton = (CWinXPButtonST*)GetDlgItem(ID) ;
if (PortFlag2[nCounter] == 100000000)
{
pWinXpButton->SetIcon(IDI_ICON3) ;
Computer(pWinXpButton->GetText(),nCounter+24, &pPortInfo) ;
//UpdateRow(nCounter+24, pWinXpButton->GetText(),&pPortInfo->Datetime,PortTime2[nCounter] - PortFirstLL2[nCounter]) ;
}
else
{
pWinXpButton->SetIcon(IDI_ICON1) ;
}
nCounter++ ;
}
if(m_b2)
ShowNoneValue() ;
}
}
void CNetworkMonitorView::ShowNoneValue()
{
nListItemIndex = 0 ;
m_ListCtrl.DeleteAllItems() ;
int nLL ;
for(int i = 0 ; i < m_PortInfo.GetSize() ; i++ )
{
if (m_PortInfo[i]->nPort > 24)
{
nLL = PortTime2[m_PortInfo[i]->nPort-24] - PortFirstLL2[m_PortInfo[i]->nPort-24] ;
}
else
{
nLL = PortTime[m_PortInfo[i]->nPort] - PortFirstLL[m_PortInfo[i]->nPort] ;
}
UpdateRow(m_PortInfo[i]->nPort, m_PortInfo[i]->sRoom,&m_PortInfo[i]->Datetime, nLL) ;
}
for(i = 0 ; i < m_NoneValue.GetSize() ; i++ )
{
m_ListCtrl.InsertItem(nListItemIndex,m_NoneValue[i]->sRoom+"(未付 僅提示一次)") ;
m_ListCtrl.SetItemText(nListItemIndex,1,m_NoneValue[i]->sTimeOnline) ;
m_ListCtrl.SetItemText(nListItemIndex,2,m_NoneValue[i]->sLL) ;
m_ListCtrl.SetItemText(nListItemIndex,3,m_NoneValue[i]->sDJ) ;
m_ListCtrl.SetItemText(nListItemIndex,4,m_NoneValue[i]->sZJ) ;
nListItemIndex++ ;
}
}
BOOL CNetworkMonitorView::Computer(CString sRoom, int nPort, PORTINFO **pPortInfo)
{
COleDateTimeSpan TimeSpan(0,0,m_nFreq,0) ;
BOOL bFlag = FALSE ;
for(int i = 0 ; i < m_PortInfo.GetSize() ; i++ )
{
if(m_PortInfo[i]->nPort == nPort)
{
bFlag = TRUE ;
m_PortInfo[i]->Datetime = m_PortInfo[i]->Datetime + TimeSpan ;
*pPortInfo = m_PortInfo[i] ;
break ;
}
}
if (!bFlag)
{
PORTINFO *pPInfo = new PORTINFO ;
pPInfo->nPort = nPort ;
pPInfo->sRoom = sRoom ;
pPInfo->Datetime.SetDateTimeSpan(0,0,0,0) ; // 包括設定時間為 00:00:00
m_PortInfo.Add(pPInfo) ;
*pPortInfo = pPInfo ;
}
return TRUE ;
}
// "房間號","上網時間","流量","單價/時","總價"} ;
void CNetworkMonitorView::UpdateRow(int nPort, CString sRomm, COleDateTimeSpan *pOleDateTime, int nLL )
{
CString sDatetime ;
CString strLL ;
CString str ;
str.Format("%d", nPort) ;
WritePrivateProfileString("nonevalue","room"+str , sRomm,".//config.ini");
int fLL = nLL ;
if (fLL < 1024)
{
strLL.Format("%dB", fLL) ;
}
else if (fLL>=1024 && fLL < 1024*1024)
{
fLL = fLL / 1024 ;
strLL.Format("%dKB", fLL) ;
}
else
{
fLL = fLL / (1024*1024) ;
strLL.Format("%dMB", fLL) ;
}
sDatetime.Format("%d天 %d時 %d分", pOleDateTime->GetDays(), pOleDateTime->GetHours(), pOleDateTime->GetMinutes()) ;
WritePrivateProfileString("nonevalue","Time"+str , sDatetime,".//config.ini");
m_ListCtrl.InsertItem(nListItemIndex,sRomm) ;
m_ListCtrl.SetItemText(nListItemIndex,1,sDatetime) ;
WritePrivateProfileString("nonevalue","LL" + str , strLL,".//config.ini");
m_ListCtrl.SetItemText(nListItemIndex,2,strLL) ;
strLL.Format("%.1f", m_fDJ) ;
m_ListCtrl.SetItemText(nListItemIndex,3,strLL) ;
WritePrivateProfileString("nonevalue","DJ" + str , strLL,".//config.ini");
float fValue = pOleDateTime->GetDays() * 24.0f ;
fValue = fValue + pOleDateTime->GetHours() + pOleDateTime->GetMinutes() / 60.0f ;
fValue = fValue * m_fDJ ;
strLL.Format("%.1f", fValue) ;
m_ListCtrl.SetItemText(nListItemIndex,4,strLL) ;
WritePrivateProfileString("nonevalue","ZJ"+str , strLL,".//config.ini");
nListItemIndex++ ;
}
void CNetworkMonitorView::SetValue(CString sIP1, CString sIP2, CString sDJ, CString sFreq)
{
m_sDJ = sDJ ;
m_sIP1 = sIP1 ;
m_sIP2 = sIP2 ;
if (m_sFreq != sFreq)
{
KillTimer(100) ;
m_nFreq = atoi(sFreq) ;
SetTimer(100,1000*60*m_nFreq,NULL) ;
}
m_sFreq = sFreq ;
}
void CNetworkMonitorView::OnDestroy()
{
CFormView::OnDestroy();
// TODO: Add your message handler code here
m_PortInfo.RemoveAll() ;
m_NoneValue.RemoveAll() ;
}
void CNetworkMonitorView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if (nIDEvent == 100)
{
SetEvent(m_GetEvent1) ;
SetEvent(m_GetEvent2) ;
ConnectionSwitch() ;
}
CFormView::OnTimer(nIDEvent);
}
void CNetworkMonitorView::OnRclickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
m_IndexItem = -1 ;
if(m_ListCtrl.GetSelectedCount()<=0)
return;
//
int ndx = 0 ;
int nItems = m_ListCtrl.GetItemCount();
while ( m_IndexItem < nItems )
{
if ( m_ListCtrl.GetItemState( ndx, LVIS_SELECTED ) == LVIS_SELECTED )
{
m_IndexItem = ndx ;
break;
}
++ndx;
}
if(m_IndexItem < 0 ) return ;
m_sRoom = m_ListCtrl.GetItemText(m_IndexItem,0);
CMenu mu,*pSubMenu;
CPoint p;
mu.LoadMenu(IDR_MENU1);
pSubMenu=mu.GetSubMenu(0);
::GetCursorPos(&p);
pSubMenu->TrackPopupMenu(TPM_LEFTALIGN,p.x,p.y,this);
*pResult = 0;
}
void CNetworkMonitorView::OnMenuJz()
{
// TODO: Add your command handler code here
m_ListCtrl.DeleteItem(m_IndexItem) ;
int nHeight = m_PortInfo.GetSize() + m_NoneValue.GetSize() ;
for(int i = 0; i < m_PortInfo.GetSize() ; i++ )
{
if(m_PortInfo[i]->sRoom == m_sRoom)
{
m_PortInfo.RemoveAt(i);
break ;
}
}
if(m_IndexItem <= m_PortInfo.GetSize() - 1 )
{
//m_PortInfo.RemoveAt(m_IndexItem) ;
}
else
{
m_IndexItem = m_IndexItem - m_PortInfo.GetSize() ;
//m_IndexItem = m_NoneValue.GetSize() - m_IndexItem - 1 ;
m_NoneValue.RemoveAt( m_IndexItem );
}
//WritePrivateProfileString("nonevalue", NULL, _T(""), ".//config.ini");
}
相關推薦
採用snmp協議 監控交換機(d-link)實現
//標頭檔案 // NetworkMonitorView.h : interface of the CNetworkMonitorView class//////////////////////////////////////////////////////////////
zabbix中用SNMP來監控交換機
前提:你要有一臺搭建好的一套zabbix伺服器,並且還有一個可監控的交換機。 一、先說下操作順序把,先要建立主機群組-->然後建立模板-->建立應用集-->建立監控項-->建立觸發器-->建立圖形,然後就把一個可以到達觸發器條件可以報警的交換機
zabbix snmp 協議監控 dell iRDAC
實驗目的: 該篇文章主要是通過zabbix snmp協議來監控dell伺服器的硬體資訊(需要啟用並且配置iRDAC功能) 先簡單瞭解下SNMP協議: 簡單網路管理協議(SNMP),由一組網路管理的標準組成,包含一個應用層協議(applic
模擬QQ聊天——採用TCP協議的C/S架構實現
模擬QQ聊天,一個伺服器處理多個客戶端的連線,同時要求各個客戶端之間能夠自由通訊。 本程式採用C/S架構,利用多執行緒完成。 伺服器端: a#include <stdio.h> #include <sys/socket.h>
用SNMP協議實現系統監控
系統監測的基本概念及分類: a.系統監測的概述: 如何對現有IT架構的整體以及細節執行情況進行科學、系統和高效地監測是目前各企業運維和管理部門一項非常重要的工作內容。隨著當前企業IT環境中伺服器、應用數量和型別的不斷地增加,運維部門需要通過科學和高效的手段儘可能詳細、實時
zabbix3.2 snmp 監控交換機流量
zabbix3.2 h3c snmp monitor 監控流量 剛開始做的時候,看網上教程很多,但都沒有總結一個,都比較碎片化,今天自己有空,就簡單匯總下,給有需要的人有個幫助1、交換機配置我就直接上圖了,我是在H3C上配置,cisco、huiwei、juniper等自己查看相關文檔2、z
Zabbix(五):高級應用-web方案、被動監控、基於snmp協議被動監控、proxy配置測試實例
zabbix proxy1.web方案web scenario:web監控方案,web場景;web scenarios指的是監控指定的web站點的資源下載及頁面響應時間等數據指標;(1)創建web監控需要先定義一個web scenario(方案):一個web方案包括一個或多個HTTP請求或步驟(steps)
採用FTP協議實現檔案的上傳
也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興! 請先明白一點,HTTP上傳和FTP上傳是不一樣的,HTTP上傳會帶有標頭檔案等等,你得分析,也就是通過網頁上傳。通過FTP上傳不用,因為他不會帶標頭檔案,操作
H3C交換機如何配置SNMP協議?
1、使用telnet 登陸裝置 system-view snmp-agent snmp-agent community read public snmp-agent sys-infoversion all dis cur save 儲存 Y 配置完成。 2.概述 SNMP 是Simple
採用HTTP協議上傳檔案實現(java)
{ 37 38 publicfinalstatic String DEFAULT_ENCODING ="ISO8859_1"; 39 40 publicfinalstatic String CHINESE_ENCODING ="GBK"; 41 42 publicfi
系統監控之SNMP協議理解
使用Mycat分散式資料庫中介軟體時需要對各個效能指標進行監控,官方已經提供了一個監控軟體,於是討論起來監控是怎麼具體可能有哪些實現,雖然知道已經有很多的監控軟體可以使用,比如zabbix,但是今天聽同事說有一個叫做SNMP的協議,是專門用在環境監控方面的,回頭
基於SNMP協議發現網路中路由器、交換機和印表機的簡單方法
在網路拓撲發現中,如何發現裝置的型別。如果一個裝置支援SNMP,就按照下面的步驟進行: 路由器發現: 決定一個裝置是否是一個路由器,通過SNMP查詢改裝置中的MIB-II中的ipAddrEntry表,如果沒有返回,就可以初步認定該裝置不是路由器,繼續通過其他
zabbix 用SNMP監控交換機
1、SNMP(簡單網路管理協議),由一組網路管理的標準組成,包含一個應用層協議(application layer protocol)、資料庫模型(database schema)和一組資源物件. 在開源監控系統中主要針對硬體的監控,比如:交換機,路由器,印表機以及網路
(筆記)Linux下網路程式設計,採用TCP協議實現的C/S架構
TCP/UDP介紹 TCP(Transfer Control Protocol)傳輸控制協議是一種面向連線的協議, 當我們的網路程式使用這個協議的時候,可以保證我們的客戶端和服務端的通訊是可靠的,安全的,適合於傳輸大批量資料的情況. UDP(User Da
NAS配置Time Machine,在D-Link DNS-320上的配置筆記
裏的 為什麽 nag 新的 finder server 詳細 一次 ont 今天打算把Time Machine備份的工作交給NAS,曾經是放在一塊外置硬盤上的。盡管速度要比NAS快。可是每次插拔外接都有些麻煩。而NAS又具有實時在線、定時關機啟動的功能。配合Time M
zabbix-3.2.6之snmp方式監控windows
pfx name local ima div pan mask bit 成功 一、在windows中添加snmp 在服務中添加public和接受服務器的IP地址。 二、在zabbix-server服務器中安裝net-snmp軟件 1、修改配置文件
使用nagios監控交換機端口流量,對低於閾值的流量進行報警
交換機 nagios snmp 需求:使用nagios服務需要對一臺思科交換機的24端口進行流量監控,當流量低於2MB/s時,發送報警;當流量高於3MB/s時,報警取消;當流量介於2MB/s-3MB/s時,處於警告warning狀態。操作方法:第一:編寫腳本文件:vim /usr/lib64/na
zabbix如何監控交換機
zabbix一、zabbix如何監控H3C:snmp-agent community read publicsnmp-agent sys-info version all二、zabbix如何監控思科:yum install net-snmp* -yenable #切換到特權模式configure termin
Zabbix監控交換機
alt 添加主機 http com images src .com ges 分享 Zabbix可以通過snmp來監控交換機 1.添加主機 成功後SNMP變綠Zabbix監控交換機
使用gulp 合並壓縮打包,實時監控文件,實現本地server
百度 合並壓縮 concat lac github install sequence rep 器) 今天不講webpack,就說說gulp是怎麽進行壓縮合並打包 首先你的安裝gulp : npm install gulp -g --save-dev 然後最基本的你因該知