2

I'm trying to build a program in c++ to see what game servers a client is connected to for a gaming site. For the program we need to be able to see if a client is connected to a specific server or not. I've tested using wireshark and this program can see the incoming/outgoing connections to and from the server - which is the exact thing I need but i'm just not sure how to do it. I understand you can see which port connections are going in and out through using command prompt using netstat, but netstat doesnt give the details i'm after. All I need to be able to do is basically scan through their outgoing connections and compare it to an IP, and if the IP matches then they're connected to the server.

Is this possible through c++? If not, does anyone know how wireshark does it?

Cheers.

CynePhoba
  • 31
  • 2

2 Answers2

1

This depends on your operating system and is different in Windows and Linux.

In Linux you can get all of the information about a program's sockets using lsof -p [PID] where PID is the program's PID.

To do this in your own program look up the lsof source code and see how it is done. As I recall, it is done by reading files in /proc.

In Windows you could try C++ Get Handle of Open Sockets of a Program

Community
  • 1
  • 1
Zan Lynx
  • 53,022
  • 10
  • 79
  • 131
0

Check out libpcap http://www.tcpdump.org/

You may need to deconstruct the UDP/TCP packets themselves.

If you want a simpler solution you could pipe the output of tcpdump as stdin. You can give tcpdump filter to ensure your application isn't spammed with useless content.

Jestor
  • 46
  • 2
  • 1
    Thankyou. I ended up finding a version of wireshark called tshark which uses command line, based of this answer - which i can then use in my program. Thankyou for your answer, it was exactly what i needed! – CynePhoba Jan 10 '14 at 04:13