Click here to Skip to main content
Click here to Skip to main content
Go to top

IP Hole Finder and Port Scanner

, 12 Mar 2001
Rate this:
Please Sign up or sign in to vote.
Security
<!-- Download Links -->
  • Download source files - 14 Kb
  • Download demo project - 60 Kb
  • Disclaimer

    The techniques discussed in this article are meant to aid Network Administrators in finding security holes in their own sysmtes in order to close potential points of weakness. These techniques must not be used to gain illegal eentry to remote servers.

    Introduction

    Internet world is full of exciting tricks and mysteries. This giant world can be more attractive when a computer programmer knows the Internet protocols and how to write codes to handle connections. We, computer programmers, know that TCP/IP protocol claims "All Hard Disks of online computers through the world are mine!" and this idea leads hackers to intrude our valuable information from any Holes on our PCs. Their hacking applications can interpret TCP/IP-based protocols such as FTP, HTTP, etc. and that is why they can do whatever with our servers. 

    What are we supposed to do to prevent their attack? If you are a network administrator, you will say that we should close unneeded ports as the first solution. In the other hand, we must find IP Holes and then close them.

    This article can give you some helpful ideas to detect these holes. The submitted code and application can be the bases of Port Scanners.

    How does it work?

    This application uses class CTheSocket inherited from class CSocket. I could use a CSocket object instead but I preferred to inherit from this class to override any desired events in the future. The member function CPortScanView::TestConnection(CString IP, UINT nPort) is the heart of port scanning. Please see the following code:

    
    BOOL CPortScanView::TestConnection(CString IP, UINT nPort)
    {
    	CTheSocket* pSocket;
    	pSocket = new CTheSocket;
    	ASSERT(pSocket);
    
    	if (!pSocket->Create())
    	{
    		delete pSocket;
    		pSocket = NULL;
    		return FALSE;
    	}
    
    	while (!pSocket->Connect(IP , nPort))
    	{
    		delete pSocket;
    		pSocket = NULL;
    		return FALSE;
    	}
    
    	pSocket->Close();
    	delete pSocket;
    	return TRUE;
    }
    
    

    In the above code if connection with the specified socket on port nPort is established, the member function will return TRUE, otherwise FALSE. This member function does not have to know Internet services protocols like HTTP, FTP, etc. to interpret them to find out whether or not the port is open. As a matter of fact the member function checks which ports are listening to establish connection. As soon as the state of socket changes from mode 'Listening' to mode 'Established' the value TRUE is reported and status 'open' is detected.

    The submitted application is a single-thread one and I used ::PeekMessage(...) at the end of the outer loop by which a range of ports can be scanned to handle windows messages in order to stop scanning process, moving windows around the screen and so on. Here, This is the code segment:

    for (m_nCounter = minPort; m_nCounter <= maxPort; m_nCounter++)
    {
    	.
    	.
    	.
    	while(nAttempt <= m_nMaxAttempts && !bIsOpen)
    	{
    		.
    		.
    	}
    	.
    	.
    	.
    	MSG message;
    	if (::PeekMessage(&message,NULL,0,0,PM_REMOVE))
    	{
    		::TranslateMessage(&message);
    		::DispatchMessage(&message);
    	}
    	.
       }
    

    To make sure that CPortScanView::OnButtonScan() is not reentered, I disabled the corresponding button CPortScanView::m_cBtnScan by invoking m_cBtnScan.EnableWindow(FALSE) member function. Also, to stop the above loop and make it exit while clicking on button CPortScanView::m_cBtnStop, I got CPortScanView::m_nCounter value to one unit more than CPortScanView::m_maxPort in message handler CPortScanView::OnButtonStop().

    Since the results of port scanning are saved in a CPtrList object member variable called CPortScanView::*m_pStatusList as a linked list, the contents of each node is not only visible in object CListCtrl::m_cResult but also accessible to save in a text file.

    The submitted code can also support UNICODE by adjusting the options and settings as described in MSDN.

    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

    Share

    About the Author

    Alex Douma
    Web Developer
    Canada Canada
    - B.S. degree in Computer Engineering.
    - 10+ years experience in Turbo C, Borland C , Visual C++ and Managed C++.
    - Obssessed in OOP style design and programming.
    - Desigining and developing Network security tools.
    - Desigining and developing a client/server appliation for sharing files among users in a way other than FTP protocol.
    - Desigining and developing ISP Subscribers account management by binding to Cisco tools (NtTac+), Reporting the results on the web by ISAPI method.
    - Designing and writing code to build a search engine (Web crawler) by SQL Server 7.0 and VC++.
     
    - On-board programming of non-boundary scan memory devices like flash memories by boundary scan (IEEE 1149.1) protocol in C# and J#.
     
    - Designing and implementing GSM gateway applications and bulk messaging.
     
    The summary of my skills:
    C#, J#, Managed C++ code, VC++, MFC, Turbo Pascal, PL/I, SQL Server, MS Access, Windows NT administration, Web site developing, Macromedia tools, Webmastering, Cisco Routers.

    Comments and Discussions

     
    QuestionHOW to modify it to scan ports on a IPv6 machine ? PinmemberAther Zaidi9-Apr-08 4:48 
    QuestionIs there a way to detect Network Printers' IP addresses? PinmemberJan Palmer25-Dec-06 20:43 
    QuestionWhy it can't work well on windowXP ? Pinmemberginkgo198012-Jun-05 20:49 
    GeneralThanks for the Code PinmemberIainws15-Jan-05 2:31 
    GeneralWaiting for long time! PinmemberR.selvam28-Nov-03 11:25 
    GeneralRe: Waiting for long time! PinsussAnonymous28-Nov-03 12:51 
    GeneralRe: Waiting for long time! PinmemberR.selvam28-Nov-03 13:46 
    GeneralIf you whant to see really good scanners Pinmemberwuxus9-Nov-03 8:32 
    GeneralRe: If you whant to see really good scanners PinmemberMichael Hendrickx26-Nov-04 8:19 
    Generalworst scaner ever. Pinmemberwukas17-Jul-03 7:59 
    GeneralRe: worst scaner ever. PinmemberArash Sabet17-Jul-03 14:20 
    GeneralRe: worst scaner ever. PinmemberXakep6-Aug-03 13:45 
    GeneralRe: worst scaner ever. PinmemberBearRiver18-Nov-04 4:39 
    GeneralRe: worst scaner ever. Pinmemberiainws15-Jan-05 2:10 
    GeneralRe: worst scaner ever. PinmemberTuPacMansur5-Sep-05 19:25 
    QuestionHow it works PinmemberSelevercin3-Apr-03 16:20 
    GeneralGood article, but a suggestion.. PinmemberSoliant29-Nov-02 8:18 
    GeneralRe: Good article, but a suggestion.. PinmemberArash Afifi29-Nov-02 13:13 
    GeneralRe: Good article, but a suggestion.. Pinmemberxxhimanshu16-Jan-03 17:44 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Mobile
    Web04 | 2.8.140905.1 | Last Updated 13 Mar 2001
    Article Copyright 2001 by Alex Douma
    Everything else Copyright © CodeProject, 1999-2014
    Terms of Service
    Layout: fixed | fluid