views:

103

answers:

3

Possible Duplicate:
Get connecting IP from specified ports that using by other program.

If a port is used by a program, is there any way I can listen that port and get the connected IP on that port?

+2  A: 
  1. No, you cannot listen on a port that another process is already listening on.
  2. But yes, you can determine the TCP/IP connections currently active on that port, as has been answered in your exact duplicate question (namely using netstat).

If this doesn't answer your question, you should try to give more information what you're trying to achieve.

dtb
Actually, there is a game server application runs on my server, it opens ports for communication with clients. I want to write a program(or other ways) to monitor these ports, get the IP addresses of the connected clients, then record them.Thank you
ED
And the answer is -- *drumroll* --: `netstat`
dtb
Or a packet sniffer, as @bua pointed out.
dtb
The problem was solved, thanks guys!
ED
A: 

I'm not sure how exactly you'd do it in code, but the information is available by running netstat -b.

jheddings
+2  A: 

You can also sniff whole network interface, and filter your related ports of interest.

bua