⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scanportdlg.cpp

📁 MD5程序
💻 CPP
字号:
// ScanPortDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ScanPort.h"
#include "ScanPortDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CScanPortDlg dialog
UINT Thread(LPVOID param){
CScanPortDlg *mys=(CScanPortDlg*)param;
	CString m_IpAddress,inf;
	BYTE a1,a2,a3,a4;
	mys->m_List.ResetContent();
	mys->m_Ip.GetAddress(a1,a2,a3,a4);
    m_IpAddress.Format("%d.%d.%d.%d",a1,a2,a3,a4);
    if(mys->m_Port1>mys->m_Port2){
      mys->m_List.AddString("端口1必须小于端口2");
	  ::EnableWindow(mys->m_bScan.m_hWnd,TRUE);
      return 0;
	}

	for(UINT i=mys->m_Port1;i<mys->m_Port2;i++){
	  	CSocket m_socket;
	  if(m_socket.Create(0,SOCK_STREAM,NULL)==TRUE)
	  {
	if(m_socket.Connect(m_IpAddress,i)==TRUE){
        inf.Format("端口 %d 开放",i);
        mys->m_List.AddString(inf);
	}
	    m_socket.Close();
	  }
	}
::EnableWindow(mys->m_bScan.m_hWnd,TRUE);
return 0;
}
CScanPortDlg::CScanPortDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CScanPortDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CScanPortDlg)
	m_Port1 = 0;
	m_Port2 =100;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CScanPortDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CScanPortDlg)
	DDX_Control(pDX, IDC_IPADDRESS1, m_Ip);
	DDX_Control(pDX, IDC_Scan, m_bScan);
	DDX_Control(pDX, IDC_LIST1, m_List);
	DDX_Text(pDX, IDC_EPort1, m_Port1);
	DDV_MinMaxUInt(pDX, m_Port1, 0, 65000);
	DDX_Text(pDX, IDC_EPort2, m_Port2);
	DDV_MinMaxUInt(pDX, m_Port2, 0, 65000);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CScanPortDlg, CDialog)
	//{{AFX_MSG_MAP(CScanPortDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_Scan, OnScan)
	ON_EN_CHANGE(IDC_EPort1, OnChangeEPort1)
	ON_EN_CHANGE(IDC_EPort2, OnChangeEPort2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CScanPortDlg message handlers

BOOL CScanPortDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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
	m_Ip.SetAddress(127,0,0,1);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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 CScanPortDlg::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 CScanPortDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CScanPortDlg::OnScan() 
{
::EnableWindow(m_bScan.m_hWnd,FALSE);
pthread=(CWinThread*)AfxBeginThread(&Thread,this,THREAD_PRIORITY_BELOW_NORMAL,0,0);			
}

void CScanPortDlg::OnChangeEPort1() 
{
UpdateData();
}

void CScanPortDlg::OnChangeEPort2() 
{
UpdateData();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -