Click here to Skip to main content
15,886,199 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
/*
	TcpScanPage.h
	Luca Piergentili, 14/07/99
	lpiergentili@yahoo.com
	http://www.geocities.com/lpiergentili/
*/
#ifndef _TCPSCANPAGE_H
#define _TCPSCANPAGE_H 1

#include "window.h"
#include "CAsyncSock.h"
#include "CListCtrlEx.h"
#include "CPropertyPageDialog.h"
#include "TcpScanConfig.h"

#define MAX_PORTLIST_STRING 2048

class CScanPage : public CPropertyPageDialog
{
	DECLARE_DYNCREATE(CScanPage)

public:
	CScanPage();
	~CScanPage();

	// gestori
	void		DoDataExchange					(CDataExchange*);	// scambio dati
	BOOL		OnInitDialog					(void);			// inizializzazione dialogo (pagina)
	BOOL		OnSetActive					(void);			// attivazione pagina
	BOOL		OnKillActive					(void);			// disattivazione pagina
	void		OnKillSheet					(void);			// chiusura sheet
	void		OnOk							(void);			// click su IDOK dello sheet
	void		OnCancel						(void);			// click su IDCANCEL dello sheet
	
	// radio buttons
	void		OnRadioButtonPortList			(void);			// lista
	void		OnRadioButtonPortRange			(void);			// intervallo

	// menu popup
	void		OnScanPopupMenuRemovePort		(void);			// IDM_SCAN_REMOVEPORT
	void		OnScanPopupMenuSaveToRegistry		(void);			// IDM_SCAN_SAVETOREGISTRY
	void		OnScanPopupMenuLoadFromRegistry	(void);			// IDM_SCAN_LOADFROMREGISTRY
	void		OnScanPopupMenuAddToServices		(void);			// IDM_SCAN_ADDTOSERVICES
	void		OnScanPopupMenuRemoveFromServices	(void);			// IDM_SCAN_REMOVEFROMSERVICES
	void		OnScanPopupMenuLoadServices		(void);			// IDM_SCAN_LOADSERVICES
	void		OnScanPopupMenuLoadFromServices	(void);			// IDM_SCAN_LOADFROMSERVICES
	void		OnScanPopupMenuClearPorts		(void);			// IDM_SCAN_CLEARPORTS

	// membri
	void		GetPropertySheetConfig			(CTcpScanConfig* pConfig) {m_pConfig = pConfig;}
	BOOL		CreateScanningList				(void);
	void		RemovePort					(void);
	BOOL		SaveScanning					(void);
	BOOL		LoadScanning					(void);

	// variabili
	CString	m_strStartHost;								// host iniziale
	CString	m_strEndHost;									// host finale
	int		m_nPortFlag;									// flag interno per selezione bottone radio
	int		m_nPortList;									// lista
	int		m_nPortRange;									// intervallo
	CString	m_strPortList;									// lista porte
	UINT		m_nStartPort;									// porta iniziale
	UINT		m_nEndPort;									// porta finale
	CListCtrlEx m_wndScanList;								// lista scanning

private:
	// gestori
	void		OnKillFocusStartHost			(void);			// imposta l'host fine con l'host inizio
	LONG		OnScan						(UINT,LONG);		// scanning dell'host

	// variabili
	CTcpScanConfig* m_pConfig;								// configurazione
	CAsyncSock* m_pAsyncSock;								// socket asincrono

	DECLARE_MESSAGE_MAP()
};

#endif // _TCPSCANPAGE_H

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