Jump to content
Tuts 4 You

[need-help] Win32 Api for enum all open Port?


pattisahusiwa

Recommended Posts

pattisahusiwa
Posted

Hi All.

I need some Win32 Api functions for enum all open port (TCP, UDP, etc) that can be implemented on XP, 7, or below. is there any function that i can be used for?

Posted

create tcp stream socket & try to connect() to it. Do that for all the ports in your range.

I dont really see any other way...

Posted

You can use the IP helper library that is part of Windows, see this MSDN link:
/>http://msdn.microsoft.com/en-us/library/windows/desktop/aa366071%28v=vs.85%29.aspx

Posted (edited)

create tcp stream socket & try to connect() to it. Do that for all the ports in your range.

I dont really see any other way...

trying to connect() to every possible existing port inside a loop is not a smart way....

i'm with kao, GetTcpTable / GetExtendedTcpTable.

Edited by rotem156
Posted

http://www.codeproject.com/Articles/5453/Enhance-netstat

The main idea of this project was already implemented and presented by some guys around here: using GetTcpTable and GetUdpTable to read connection states of running processes. Yet another thing that is mentioned in this kind of articles are two undocumented APIs from iphlpapi.dll: AllocateAndGetTcpExTableFromStack and AllocateAndGetUdpExTableFromStack. Using these APIs, we can get access to the name of the process that holds the running connection. Unfortunately it does work only with Win2000, WinXP or newer versions.

Amazing what happens if you actually perform a Google search for something relating to this subject, like: "Detect open ports C++"

HR,

Ghandi

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...