Jump to content

This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.

How to determine which TCP ports are listening?

2 replies to this topic


  • Members
  • 26 posts

Posted 28 March 2003 - 20:39

Is there anyway to programmatically determine which TCP ports are currently actively in a LISTENING state?  I can do this with netstat -an -p tcp of course but I wanted to put this into a DLL function.  I've tried playing around with the MFC CSocket class.  But I'm finding that calls to Create() and Listen() on the port will success on ports that are in the LISTENING state -- just not on ports with ESTABLISHED sessions.  I want to find a way to make sure that the port a user is allowed to select is not in a LISTENING state at all to hopefully preclude any conflicts later.  Thanks in advance!


  • Full Members
  • 35 posts

Posted 14 April 2003 - 14:32

I also used netstat for this. Piped the output and used grep to find lines with portnumber and listening. Works fine for me. I didnt find any better way to do this.


  • Members
  • 3 posts

Posted 24 April 2003 - 10:30

There is a tool, TCPView, a Windows program that shows you detailed listings
of all TCP and UDP endpoints on your system.

Source code of this usefull tool is not available but the command line version demonstrates
the MSDN IP Helper interface and is available here for download with source: I think it's a
good starting point (look at the bottom of the page).