Click here to Skip to main content
15,891,943 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 163K   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
/*
	TcpServicesPage.h
	Luca Piergentili, 14/07/99
	lpiergentili@yahoo.com
	http://www.geocities.com/lpiergentili/
*/
#ifndef _TCPSERVICESPAGE_H
#define _TCPSERVICESPAGE_H 1

#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "strcpyn.h"
#include "window.h"
#include "CSock.h"
#include "CNodeList.h"
#include "CTextFile.h"
#include "CListCtrlEx.h"
#include "CPropertyPageDialog.h"
#include "TcpMessages.h"
#include "TcpScanConfig.h"
#include "TcpScanPage.h"
#include "TcpScanAddServiceDlg.h"
#include "resource.h"

#define SERVICES_FROM_REGISTRY 0
#define SERVICES_FROM_DATABASE 1

class CServicesPage : public CPropertyPageDialog
{
	DECLARE_DYNCREATE(CServicesPage)

public:
	CServicesPage();
	~CServicesPage();
	
	// 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

	// menu popup
	void		OnServicesPopupMenuAddPort		(void);			// IDM_SERVICES_ADDPORT
	void		OnServicesPopupMenuLoadAllPorts	(void);			// IDM_SERVICES_LOADALLPORTS
	void		OnServicesPopupMenuSetStartPort	(void);			// IDM_SERVICES_SETSTARTPORT
	void		OnServicesPopupMenuSetEndPort		(void);			// IDM_SERVICES_SETENDPORT
	void		OnServicesPopupMenuClearPorts		(void);			// IDM_SERVICES_CLEARPORTS
	void		OnServicesPopupMenuAddService		(void);			// IDM_SERVICES_ADDSERVICE
	void		OnServicesPopupMenuRemoveService	(void);			// IDM_SERVICES_REMOVESERVICE
	void		OnServicesPopupMenuSaveToRegistry	(void);			// IDM_SERVICES_SAVETOREGISTRY
	void		OnServicesPopupMenuLoadFromRegistry(void);			// IDM_SERVICES_LOADFROMREGISTRY
	void		OnServicesPopupMenuSaveToDatabase	(void);			// IDM_SERVICES_SAVETODATABASE
	void		OnServicesPopupMenuLoadFromDatabase(void);			// IDM_SERVICES_LOADFROMDATABASE

	// membri
	void		GetPropertySheetConfig			(CTcpScanConfig* pConfig) {m_pConfig = pConfig;}
	BOOL		AddService					(SERVICES* = NULL);
	BOOL		RemoveService					(SERVICES* = NULL);
	BOOL		LoadServices					(int);
	BOOL		SaveServices					(int);
	
	// variabili
	CString m_strServicesDatabase;							// IDC_COMBO_SERVICES
	CListCtrlEx m_wndServicesList;							// IDC_LIST_SERVICES

private:
	// gestori
	void		OnButtonServices				(void);			// seleziona il database dei servizi

	// membri
	BOOL		LoadServicesFromDatabase			(const char*);		// carica i servizi dal database
	BOOL		LoadServicesFromRegistry			(void);			// carica i servizi dal registro
	BOOL		SaveServicesToDatabase			(const char*);		// salva i servizi nel database
	BOOL		SaveServicesToRegistry			(void);			// salva i servizi nel registro

	// variabili
	int m_nMaxDatabaseEntry;									// numero max di files per il combo
	CServicesList* m_pServiceList;							// lista per i servizi
	CTcpScanConfig* m_pConfig;								// configurazione

	DECLARE_MESSAGE_MAP()
};

#endif // _TCPSERVICESPAGE_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