intelliproject logo

Location: Desktop development - C/C++    License: The Intelliproject Open License (IPOL)

Check if a specific TCP or UDP port is open

Posted by Silviu Caragea

Describe a very simple way that you can use to check if a specific TCP or UDP port is open

Skill: Intermediate

Posted: 08/10/2008

Views: 2152

Rating: 5.00 /5

Popularity: 0.00

Sign Up to vote for this article

Introduction

This article will show you how to scan in c++ a TCP or UDP port to see if it’s open.

The TCP (Transmission Control Protocol ) is intended to provide a reliable process-to-process communication service in a multinetwork environment.  The TCP is intended to be a host-to-host protocol in common use in multiple networks.

User Datagram Protocol (UDP) is one of the core protocols of the Internet Protocol Suite. Using UDP, programs on networked computers can send short messages sometimes known as datagrams (using Datagram Sockets) to one another.

UDP does not guarantee reliability or ordering in the way that TCP does. Datagrams may arrive out of order, appear duplicated, or go missing without notice. Avoiding the overhead of checking whether every packet actually arrived makes UDP faster and more efficient, for applications that do not need guaranteed delivery.

How to use this code

To use this code you should include windows.h and to link the Wsock32 library as follows: 

1. Check TCP Port

2. Check UDP Port

Before using any socket functions call WSAStartup. The WSAStartup function must be the first Windows Sockets function called by an application or DLL. It allows an application or DLL to specify the version of Windows Sockets required and to retrieve details of the specific Windows Sockets implementation. The application or DLL can only issue further Windows Sockets functions after a successfully calling WSAStartup.

You can call WSAStartup as follow:

License

This article, along with any associated source code and files, is licensed under The Intelliproject Open License (IPOL)

About the author

Silviu Caragea

Silviu Caragea is the Founder, Administrator and Chief Editor who wrote and runs The IntelliProject.

He's been programming since 2000 and now he's student at The Faculty of Economic Cybernetics, Statistics and Informatics from Bucharest. In the same time he's working as software developer at Cratima Software, a Romanian software and web design company that activates both on the local and foreign market, providing its customers with software development services, internet and intranet solutions, web design, graphic design and IT consultancy.

His programming experience includes:
- C,C++, Visual C++(Win32 API, MFC, ADO, STL, DAO, ODBC, ATL, COM, DirectShow, DirectDraw, WTL)
- Open Source libraries :CURL & Boost
- HTML, CSS
- Java (SE,ME)
- JavaScript, Ajax, Google Web Toolkit (GWT)
- Php, MySQL
-Oracle, PL SQL
- C# .NET
-Objective C, IPhone SDK, Cocoa

Location: Romania
Ocupation: Software Engineer
Home page: http://www.intelliproject.net

Posted by Vassileios at 10/01/2009 09:01
very nice and usefull...

Sign up to post message on the article message board!