?? cscanportdlg.cpp
字號:
// CScanPortDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CScanPort.h"
#include "CScanPortDlg.h"
#include "HELPDialog.h"
#ifdef _DEBUG
#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 void OnClose();
//}}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)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCScanPortDlg dialog
CCScanPortDlg::CCScanPortDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCScanPortDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCScanPortDlg)
m_vIP = _T("");
m_vport = _T("");
m_context = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCScanPortDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCScanPortDlg)
DDX_Control(pDX, IDC_IPADDRESS_END, m_End);
DDX_Control(pDX, IDC_IPADDRESS_START, m_Start);
DDX_Control(pDX, IDC_TREE_RESULT, m_cTreeResult);
DDX_Control(pDX, IDC_STATIC_START, m_cEndTime);
DDX_Control(pDX, IDC_STATIC_END, m_cStartTime);
DDX_Control(pDX, IDC_STATIC1, m_cc);
DDX_Control(pDX, IDC_Groupe, m_cGrope);
DDX_Control(pDX, IDC_EDIT_ATTEMPTS, m_cAttempts);
DDX_Control(pDX, IDC_EDIT_TOPORT, m_cPortTo);
DDX_Control(pDX, IDC_EDIT_FORMPORT, m_cPortFrom);
DDX_Control(pDX, IDC_EDIT_SINGLEPORT, m_cSinglePort);
DDX_Control(pDX, IDC_PROGRESS, m_cProgress);
DDX_Control(pDX, IDC_BUTTON_STOP, m_cBtnStop);
DDX_Control(pDX, IDC_BUTTON_SCAN, m_cBtnScan);
DDX_Text(pDX, IDC_EDIT_IP, m_vIP);
DDV_MaxChars(pDX, m_vIP, 32);
DDX_Text(pDX, IDC_EDIT_PORT, m_vport);
DDV_MaxChars(pDX, m_vport, 65536);
DDX_Text(pDX, IDC_EDIT_CONTEXT, m_context);
DDV_MaxChars(pDX, m_context, 65566);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCScanPortDlg, CDialog)
//{{AFX_MSG_MAP(CCScanPortDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_SCAN, OnButtonScan)
ON_BN_CLICKED(IDC_RADIO_SINGLEPORT, OnRadioSingleport)
ON_BN_CLICKED(IDC_RADIO_RANGEPORT, OnRadioRangeport)
ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
ON_WM_DESTROY()
ON_COMMAND(ID_OPEN, OnOpen)
ON_COMMAND(ID_EXIT, OnExit)
ON_COMMAND(ID_HELP, OnHelp)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_RESULT, OnSelchangedTreeResult)
ON_BN_CLICKED(IDC_BUTTON_Attack, OnBUTTONAttack)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCScanPortDlg message handlers
BOOL CCScanPortDlg::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
// TODO: Add extra initialization here
m_cPortFrom.EnableWindow(FALSE);
m_cPortTo.EnableWindow(FALSE);
m_cSinglePort.EnableWindow(FALSE);
m_cAttempts.EnableWindow(FALSE);
m_bStart=FALSE;
return TRUE; // return TRUE unless you set the focus to a control
}
void CCScanPortDlg::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 CCScanPortDlg::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 CCScanPortDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CCScanPortDlg::TestConnection(CString IP , UINT nPort)
{
SOCKADDR_IN dest;
memset(&dest,0,sizeof(dest));
dest.sin_addr.S_un.S_addr=inet_addr(IP);
dest.sin_port=htons(nPort);
dest.sin_family=AF_INET;
SOCKET hsock=socket(AF_INET,SOCK_STREAM,0);
int error=connect(hsock,(sockaddr*)(&dest),sizeof(SOCKADDR_IN));
if(error!=-1) return FALSE;
closesocket(hsock);
return TRUE;
}
CString CCScanPortDlg::GetIPAddress( BYTE f1,BYTE f2,BYTE f3,BYTE f4 )
{
CString IP;
char temp[10]=_T("\0");
IP=_itoa(f1,temp,10);
IP+=_T(".");
IP+=_itoa(f2,temp,10);
IP+=_T(".");
IP+=_itoa(f3,temp,10);
IP+=_T(".");
IP+=_itoa(f4,temp,10);
return IP;
}
void CCScanPortDlg::OnButtonScan()
{
// TODO: Add your control notification handler code here
CString btnTxt,IP;
UINT nSinglePort ,maxPort,minPort,nIndex=0,nCounter;
BYTE sf1,sf2,sf3,sf4,ef1,ef2,ef3,ef4;
TCHAR temp[10]="\0";
m_cTreeResult.DeleteAllItems();
m_cTreeResult.SetBkColor(RGB(255,200,200));
SetDlgItemText(IDC_STATIC_START,"開始時間");
SetDlgItemText(IDC_STATIC_END,"結束時間");
CTime time=CTime::GetCurrentTime();
int nhs=time.GetHour();
int nms=time.GetMinute();
int nss=time.GetSecond();
char temps[10]=_T("\0");
TV_INSERTSTRUCT TreeCtrlItem;
HTREEITEM hTreeItem;
CString strs;
// 當小時小于10時,在它的前面加上0
if(nhs<10)
{
strs+=_T("0");
strs+=itoa(nhs,temps,10);
}
else
{
strs+=itoa(nhs,temps,10);
}
strs+=":";
// // 當分小于10時,在它的前面加上0
if(nms<10)
{
strs+=_T("0");
strs+=itoa(nms,temps,10);
}
else
{
strs+=itoa(nms,temps,10);
}
strs+=":";
// 當秒小于10時,在它的前面加上0
if(nss<10)
{
strs+=_T("0");
strs+=itoa(nss,temps,10);
}
else
{
strs+=itoa(nss,temps,10);
}
SetDlgItemText(IDC_STATIC_START,strs);
m_cProgress.SetPos(0);
if(m_Start.IsBlank())
{
MessageBox(_T("Please specify the machine's IP address"),_T("Error"),MB_OK|MB_ICONEXCLAMATION);
return;
}
if(m_Start.GetAddress(sf1,sf2,sf3,sf4)<4)
{
MessageBox(_T("Please specify the IP address again!"),_T("Invalid IP address!"),MB_OK|MB_ICONEXCLAMATION);
return;
}
if(m_End.IsBlank())
{
MessageBox(_T("Please specify the machine's IP address"),_T("Error"),MB_OK|MB_ICONEXCLAMATION);
return;
}
if(m_End.GetAddress(ef1,ef2,ef3,ef4)<4)
{
MessageBox(_T("Please specify the IP address again!"),_T("Invalid IP address!"),MB_OK|MB_ICONEXCLAMATION);
return;
}
m_cBtnStop.EnableWindow();
m_cBtnScan.EnableWindow(FALSE);
if(m_bSinglePort)
{
CString port;
m_cSinglePort.GetWindowText(port);
maxPort=minPort=nSinglePort=atoi(port);
if( nSinglePort<=0||nSinglePort>65566 )
{
MessageBox(_T("Please specify the Port !"),_T("Invalid Port address!"),MB_OK|MB_ICONEXCLAMATION);
m_cBtnStop.EnableWindow(FALSE);
m_cBtnScan.EnableWindow();
m_cSinglePort.SetWindowText((CString)_T(" "));
return;
}
}
else
{
CString port1,port2;
m_cPortFrom.GetWindowText(port1);
m_cPortTo.GetWindowText(port2);
minPort=atoi(port1);
maxPort=atoi(port2);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -