473,395 Members | 1,791 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,395 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 17580
"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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.