Listen to a port

thomas10001

Well-known member
Joined
Jun 22, 2003
Messages
57
Location
Samoa & Sweden
I want to listen (read data) from a port that is in use on my computer.

How can I do this? I want to find out what is sent to my port from another server.

I have tried to make simple program using sockets. But I am not able to read any data.

I have also tried to connect with telnet and other software but without any result.

If I want to listen to a port that is in use sending/receiving data, should I connect to my local port or to the server is one question.

Even if the port is in use, shouldnt I be able to connect to it and read the data somehow?
 
A port is just a process identifier, therefore only one process can use a particular port at any one time. If a port is in use by a program, then a second program trying to use that same port will experience problems. In .NET an exception is thrown if a port is already in use when you try to use it.

It sounds to me that you want to eavesdrop on the data flowing to a local process. This is going to be somewhat complicated. Example: most web servers typically listen on port 80. This port is typically used for setting up new processes (for each connection request). When a user requests a web page, their initial TCP request comes in on port 80. The webserver spawns a new TCP session on an available port and instantly closes the communication on port 80. Most servers, regardless of type, function in this manner. They dont send their data on the default port. If they did, no new clients would be able to connect if a different client was actively connected. So, to answer your question, you are going to have to programmatically find processes spawned by the parent process in question. Once you do that, you will have to find what ports they are using and then passively capture the data -- which is probably not easily done in .NET.
 
It sounds to me that you want to eavesdrop on the data flowing to a local process. This is going to be somewhat complicated. Example: most web

Yes that is what I want to do.

you will have to find what ports they are using and then passively capture the data -- which is probably not easily done in .NET.[/QUOTE]

I have a software that displays the ports used.
But it is possible to do? Should I listen to the port on my computer or on the remote end? Does it matter?

Any hints how to do this?
 
Probably the local end, but not all TCP traffic is bidirectional. It would depend on the type of server it is. Also, I dont know how youre going to "listen" to data flowing to a local port if it is already being used. I posted about putting your NIC into promiscuous mode and using some Windows system libraries to monitor data on your local network segment. You may want to check that out.
 
Back
Top