Click here to Skip to main content
15,886,026 members
Articles / Desktop Programming / MFC

How to write a simple but effective TCP/IP port scanner for Win32

Rate me:
Please Sign up or sign in to vote.
4.82/5 (15 votes)
27 Oct 20017 min read 162.8K   7.3K   101  
An article on how to write a TCP/IP port scanner with a GUI, based on the MFC's property sheet paradigm
/*
	TcpScanAddUrlDlg.cpp
	Luca Piergentili, 06/08/98
	lpiergentili@yahoo.com
	http://www.geocities.com/lpiergentili/
*/
#include "env.h"
#include "pragma.h"
#include "TcpScanAddUrlDlg.h"

BEGIN_MESSAGE_MAP(CTcpScanAddUrlDlg,CDialog)
	ON_BN_CLICKED(IDOK,OnButtonAdd)
	ON_BN_CLICKED(IDCANCEL,OnButtonCancel)
END_MESSAGE_MAP()

/*
	DoDataExchange()
*/
void CTcpScanAddUrlDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);

	DDX_Text(pDX,IDC_EDIT_URL,*m_pstrURL);
	DDX_Text(pDX,IDC_EDIT_COMMENT,*m_pstrComment);
}

/*
	CTcpScanAddUrlDlg()
*/
CTcpScanAddUrlDlg::CTcpScanAddUrlDlg(CWnd* pParent,CString& pURL,int nMaxURL,CString& pComment,int nMaxComment) : CDialog(CTcpScanAddUrlDlg::IDD,pParent)
{
	m_pstrURL = &pURL;
	m_nMaxURL = nMaxURL;
	m_pstrComment = &pComment;
	m_nMaxComment = nMaxComment;
}

/*
	OnInitDialog()
*/
BOOL CTcpScanAddUrlDlg::OnInitDialog(void)
{
	// chiama il gestore originale
	CDialog::OnInitDialog();

	// icona di default
	m_hIcon = AfxGetApp()->LoadIcon(IDI_TCPSCAN);
	SetIcon(m_hIcon,TRUE);
	SetIcon(m_hIcon,FALSE);

	return(TRUE);
}

/*
	OnButtonAdd()
*/
void CTcpScanAddUrlDlg::OnButtonAdd(void)
{
	BOOL flag = TRUE;

	UpdateData(TRUE);

	if(m_pstrURL->GetLength() <= 0 || m_pstrURL->GetLength() >= m_nMaxURL)
	{
		CString c;
		c.Format("Must enter valid URL with a length between %d and %d.",1,m_nMaxURL);
		AfxMessageBox(c,MB_ICONWARNING);
		flag = FALSE;
	}

	if(m_pstrComment->GetLength() <= 0)
		*m_pstrComment = " ";
	else if(m_pstrComment->GetLength() >= m_nMaxComment)
	{
		CString c;
		c.Format("Comment's length must be between %d and %d.",1,m_nMaxComment);
		AfxMessageBox(c,MB_ICONWARNING);
		flag = FALSE;
	}

	if(flag)
		EndDialog(IDOK);
}

/*
	OnButtonCancel()
*/
void CTcpScanAddUrlDlg::OnButtonCancel(void)
{
	EndDialog(IDCANCEL);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Italy Italy
I like C and C++, Acid Jazz, James Brown, gli Spaghetti Aglio e Olio, alla Bolognesa, alla Puttanesca e le Fettuccine alla Matriciana ('Maccaroni' over the world). Of course I like beautiful big tits girls too, my little car, Frank Zappa, the art of Zen, italian coffee and much more...

Comments and Discussions