I would like to write an application like a netstat – to show all the active connections and the open ports respectively. The problem is that I don’t know how to do it – I’ve done some network programming but in general it was some simple server-client packet and simple TCP and UDP packets sending/receiving.
I looked at the netstat code but it looks really complex. I am also reading the Unix Network Programming book and waiting for my copies of TCP/IP Illustrated (the 1 and 2 vol).
Any advice guys ? Anyone’s got experience with stuff like this ? If does, can someone help me a bit in here ? The important things to do etc. etc. ? I’ll appreciate every helpful answer.
Thank you in advance.
You can do this, but realize that implementation will be operating system specific. This is because every OS exposes its counters and statistics differently.
For example, on Linux, you can get most of the statistics by parsing the files in
/proc/net. Dumping the contents of/proc/net/devgives you the list of interfaces (along with some stats).Or, parsing
/proc/net/netstatwill give you protocol (TCP/IP) statistics:Or
/proc/net/udpgives you UDP connection information:Hope this helps.