473,804 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 17692
"Werner Schmidt" <in*******@MADD .gmx.dewrote in message
news:OX******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP03.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********@myw ay.comwrote in message
news:11******** **************@ j72g2000cwa.goo glegroups.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 GetExtendedTcpT able 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********@myw ay.comwrote in message
news:11******** **************@ j72g2000cwa.goo glegroups.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 GetExtendedTcpT able 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()

AllocateAndGetT cpExTableFromSt ack()

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

Now my problem is, that under Windows 2000 I can't use
AllocateAndGetT cpExTableFromSt ack() or GetExtendedTcpT able() 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********@my way.comwrote in message
news:11******* *************** @j72g2000cwa.go oglegroups.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 GetExtendedTcpT able 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
6506
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, and that extension is not enabled in many places. I need some way for a process to uniquely identify itself. It can then look at the storage container (flat file, DB, whatever is appropriate in context), check to see if the requested semaphore...
21
15736
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 1234, but each instance binds to a different ip address. that is to say: instance #1 binds to 192.168.1.5/port 1234 instance #2 binds to 192.168.1.6/port 1234 instance #3 binds to 192.168.1.7/port 1234
5
4046
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 can I get the number of the dynamic port in the server (in server code)? Using LocalEndPoint.Port just returns the original listener port number. Thanks,
18
4897
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) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
3
2681
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 back when A2.0 was more widely used, so the code is Access Basic. Autodialer is not the answer, as it requires users to take handsets off-hook manually. I find myself in need of more direct control of a voice/data/fax modem from an A97 program....
6
3129
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 to access a socket in a way fobidden by its access permissions."
9
13578
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
3708
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 spawns a subprocess with the computation). Now, if the computation has a result I would like to display it in the front end. In another words, I would like to pass some data from one process to another. How to do that? I'm affraid I can't use a...
3
3902
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. This stays the same as each thread is opened up. After 3 or 4 are open the numbers are the same. How can I get the number of threads if this doesn't work? Thanks,
0
9704
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10561
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7608
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.