How to get a process tcp port number

W

Werner Schmidt

Dear group,

I have the following scenario:

I have an application - let's call it myApp.exe - that is listening on a
specific port - let's say 10000.

Now I need a way to get the port number of myApp.exe (perhaps with WMI,
API, etc.).

Is there a way to handle this?


I can see the port myApp.exe is listening through a tool called tcpview.

Hope you can help me.

Best regards,

Werner
 
W

Willy Denoyette [MVP]

Werner Schmidt said:
Dear group,

I have the following scenario:

I have an application - let's call it myApp.exe - that is listening on a specific port -
let's say 10000.

Now I need a way to get the port number of myApp.exe (perhaps with WMI, API, etc.).

Is there a way to handle this?


I can see the port myApp.exe is listening through a tool called tcpview.

Hope you can help me.

Best regards,

Werner

From the command line: netstat -o returns the listeners IP address and port and PID,
netstat -b returns the process name instead of the PID.

Willy.
 
G

garyusenet

How do you do this programatically? (determine port that is not launch
netstat).
 
W

Willy Denoyette [MVP]

How do you do this programatically? (determine port that is not launch
netstat).

By calling into iphlpapi.dll using PInvoke interop.
Google around for GetExtendedTcpTable and iphlpapi.dll, I'm sure you will find some existing
stuff.

Willy.
 
W

Werner Schmidt

Here are some API-Methods for my purposes:

GetTcpTable()

AllocateAndGetTcpExTableFromStack()

GetExtendedTcpTable()


I wrote a small programm that is able to show me all Processes with the
belonging TCP-Ports (with AllocateAndGetTcpExTableFromStack()) running
under Windows XP.

Now my problem is, that under Windows 2000 I can't use
AllocateAndGetTcpExTableFromStack() or GetExtendedTcpTable() so I'm only
able to use GetTcpTable() to list all TCP-Ports but without the
belonging processes.

Did somebody have the same problem or is there another way (.Net or WMI
etc.) to solve my problem?

Thanks in advance,

Werner
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top