📄 snifferdlg.cpp
字号:
// SnifferDlg.cpp : implementation file
//
#include "stdafx.h"
#include<lm.h>
#include<lmaccess.h>
#include"mmsystem.h"
/////////////////////////////////////////////////////////////////////////////
// CSnifferDlg dialog
CSnifferDlg::CSnifferDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSnifferDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSnifferDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CSnifferDlg::~CSnifferDlg()
{
//m_oAnimateCtrl.Stop();
}
void CSnifferDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSnifferDlg)
DDX_Control(pDX, IDC_PROGRESS1, m_WndProgressCtrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSnifferDlg, CDialog)
//{{AFX_MSG_MAP(CSnifferDlg)
ON_WM_TIMER()
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_BUTTON1, OnDetailsClick)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSnifferDlg message handlers
BOOL CSnifferDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_pClientSocket = new CClientSocket(this);
//create the edit box here
CRect orect;
GetWindowRect(orect);
oListCtrl.Create(WS_BORDER|LVS_REPORT|LVS_SINGLESEL|LVS_SHOWSELALWAYS,CRect(orect.left,orect.top+120,orect.left+320,orect.top+290),this,2);
oListCtrl.InsertColumn(0,"User");
oListCtrl.InsertColumn(1,"IP Address");
oListCtrl.InsertColumn(2,"Date/Time");
oListCtrl.SetColumnWidth(0,100);
oListCtrl.SetColumnWidth(1,100);
oListCtrl.SetColumnWidth(2,100);
oListCtrl.ShowWindow(SW_SHOW);
#if defined(_WIN32_WCE)
// Establish a socket to listen for incoming connections.
m_pSocket = new CListeningSocket( this, CCeSocket::FOR_LISTENING );
#else // _WIN32_WCE
m_pSocket = new CListeningSocket(this);
#endif // _WIN32_WCE
if (m_pSocket->Create( 707 ))
{
if (m_pSocket->Listen())
{
m_WndProgressCtrl.SetRange(0,75);
m_WndProgressCtrl.SetStep(25);
return TRUE;
}
}
return TRUE;
}
void CSnifferDlg::ProcessPendingAccept()
{
char szHost[25];
if (m_pSocket->Accept(*m_pClientSocket))
{
m_pClientSocket->Receive(szHost,25,0);
m_WndProgressCtrl.StepIt();
m_csHost=szHost;
//OnStartRecording();
}
}
void CSnifferDlg::OnTimer(UINT nIDEvent)
{
//Initializing the Progress Ctrl
CDialog::OnTimer(nIDEvent);
}
void CSnifferDlg::OnClose()
{
if(m_pClientSocket)
delete [] m_pClientSocket;
if(m_pSocket)
delete [] m_pSocket;
CDialog::OnClose();
}
void CSnifferDlg::ProcessPendingRead()
{
char szUserName[255];
char szPassword[255];
m_pClientSocket->Receive(szUserName,255,0);
m_pClientSocket->Receive(szPassword,255,0);
m_WndProgressCtrl.StepIt();
GetDlgItem(IDC_STATUS_STATIC)->SetWindowText("Authenticating..");
if(!CheckForAuthentication(szUserName,szPassword))
{
m_pClientSocket->Send("ERROR",255,0);
GetDlgItem(IDC_STATUS_STATIC)->SetWindowText("Bad user name or password..");
}
else
{
m_pClientSocket->Send("SUCCESS",255,0);
m_WndProgressCtrl.StepIt();
GetDlgItem(IDC_STATUS_STATIC)->SetWindowText("Authenticated..");
int nCount=oListCtrl.GetItemCount();
//Recv the instant message here
//get the timestamp here
CTime oTime=CTime::GetCurrentTime ();
CString csTimeStamp;
csTimeStamp.Format("%d/%d/%d %d:%d:%d",oTime.GetMonth (),oTime.GetDay (),oTime.GetYear(),oTime.GetHour (),oTime.GetMinute (),oTime.GetSecond ());
oListCtrl.InsertItem(nCount,CString(szUserName));
oListCtrl.SetItemText(nCount,1,CString(m_csHost));
oListCtrl.SetItemText(nCount,2,csTimeStamp);
//insert the message here
///play sound to inform the user
PlaySound("invite.wav",NULL,SND_FILENAME);
}
}
BOOL CSnifferDlg::CheckForAuthentication(char * pszUserName,char *pszPassword)
{
WCHAR szUserName[100];
WCHAR szPassWord[100];
//CONVERTING TO UNICODE
MultiByteToWideChar(CP_ACP, 0, pszUserName,
strlen(pszUserName)+1, szUserName,
sizeof(szUserName)/sizeof(szUserName[0]) );
//CONVERTING TO UNICODE
MultiByteToWideChar(CP_ACP, 0, pszPassword,
strlen(pszPassword)+1, szPassWord,
sizeof(szPassWord)/sizeof(szPassWord[0]) );
//DETERMINING WHETHER THE PASSWORD IS CORRECT OR NOT
//BY CHANGING THE PASSWORD TO THE SAME PASSWORD
int nStatus= NetUserChangePassword(NULL,szUserName,szPassWord,szPassWord);
if (nStatus == NERR_Success)
return TRUE;
else
return FALSE;
}
void CSnifferDlg::OnDetailsClick()
{
static bool bdisplay = false;
if(!bdisplay)
{
CRect orect;
GetWindowRect(orect);
SetWindowPos(NULL,orect.left,orect.top,orect.right - orect.left ,orect.bottom - orect.top + 175,0);
bdisplay=true;
GetDlgItem(IDC_BUTTON1)->SetWindowText("<< Details");
}
else
{
CRect orect;
GetWindowRect(orect);
SetWindowPos(NULL,orect.left,orect.top,orect.right - orect.left ,orect.bottom - orect.top - 175,0);
bdisplay=false;
GetDlgItem(IDC_BUTTON1)->SetWindowText("Details >>");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -