I am trying to build a network monitoring application using vb.net (framework 4.5). I would like to be able to see a listing of all active connections, with their local/remote ports, IPs, and associated applications, etc... Ideally I wouldn't have to use a timer to refresh the data, there would be some event that would fire when connections are opened or closed.
I have been researching different ways of possible accomplishing this on the web and was hoping someone could help me decide on the best approach. And maybe provide some examples if they exists.
Option #1: Shell out to a netstat command
Pros: Simple, and includes the PID
Cons: Not managed code, and no way to identify opening and closing connections.
Option #2: Use the TcpConnectionInformation class
Pros: Simple, managed code
Cons: No PID, and no way to identify opening and closing connections
Option #3: Using ShappCap or pCap.NET
Pros: Seems like it will let me identify when new connections are opened
Cons: Very Complex, includes a lot more then i need.
Options 1 & 2 seem to be the simplest, but I haven't been able to find a way to identify when a connection is opened or closed. Option 2 would be my preference, but doesn't seem to give access to the process ID. Option #3 seems like it might let me accomplish what i am trying to do, but seems like it would introduce a lot more complexity and overhead then i need.
The main items i am missing is being able to have a event tell me when a connection is opened or closed, and getting the PID. Are either of those possible using the TcpConnectionInformation class?
Thanks in advance..