I’d like to write a Java program that will list all open network connection on a machine, in a host:port pattern.
Incoming connections are more important, but outgoing connections are nice to have as well.
Currently I have 2 options in mind:
- Use jpcap to monitor all packets and get the host:port of incomingoutgoing network connections out of it. I’m afraid that this option is a bit of an overkill and will have performance implication.
- Use netstat (or similar commands per OS type) and parse it. Per this option, I also thought of using SIGAR, but as for now I was only able to get some netstat metrics rather than a list of network connections.
This options seems pretty easy to implement and straight forward, but I’m afraid I’m missing something here.
Do you guys have a different idea, or any recommendation or comments as to the two options?