473,412 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

How to get a process tcp port number

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
Dec 8 '06 #1
5 17581
"Werner Schmidt" <in*******@MADD.gmx.dewrote in message
news:OX**************@TK2MSFTNGP03.phx.gbl...
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.

Dec 8 '06 #2
How do you do this programatically? (determine port that is not launch
netstat).

Willy Denoyette [MVP] wrote:
"Werner Schmidt" <in*******@MADD.gmx.dewrote in message
news:OX**************@TK2MSFTNGP03.phx.gbl...
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.
Dec 8 '06 #3
<ga********@myway.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
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.

Dec 8 '06 #4
Thank you very much, Willy. I will give it a try.

Best regards,

Werner

Willy Denoyette [MVP] schrieb:
<ga********@myway.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
>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.
Dec 11 '06 #5
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

Werner Schmidt schrieb:
Thank you very much, Willy. I will give it a try.

Best regards,

Werner

Willy Denoyette [MVP] schrieb:
><ga********@myway.comwrote in message
news:11**********************@j72g2000cwa.googleg roups.com...
>>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.
Dec 11 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Joshua Beall | last post by:
Hi All, I am doing some work where I want to do locking, and prevent scripts from running in parallel. I see that I could use the semaphore mechanism, but I'd like for my code to be portable,...
21
by: Alexander N. Spitzer | last post by:
If I have a machine with 3 virtual IP addresses (192.168.1.), how can I start 3 instances of the same RMI application (each started with different properties/configs), each listening on the port...
5
by: Jason | last post by:
After a server accepts a client connection on a certain port, a new socket is created on the server on a system managed dynamic port to handle the connection. Please confirm this. If so, how...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
3
by: MLH | last post by:
I found some code Dev Ashish posted nearly a decade ago in response to someone's inquiry describing their need to dial a number, monitor call progress and determine whether it was busy. This was...
6
by: kai | last post by:
Hi, I was tring to run an example (HelloWorld.aspx) from MSPrss book, I get this message: "ASP.NET Development Server faild to start listening port 1034. Error message: An attempt was made...
9
by: xparrot1 | last post by:
I know that I can get the SERVER port number like this: HttpContext.Current.Request.ServerVariables My question is how do I get the remote CLIENT port number? Thanks Derek
6
by: ecir.hana | last post by:
Hi, let's say I have two scripts: one does some computations and the other one is a graphical front end for launching the first one. And both run in separate processes (front end runs and that it...
3
by: tshad | last post by:
I need to find out how many threads a process has. I have used ThreadPool.GetAvailableThreads and ThreadPool.GetMaxThreads, but they both show 50 for worker threads and 100 for port threads. ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.