TCP Event Monitor in .NET
I have a SysTray application that needs to know when a browser runs into an Internet TImeout/Connecti开发者_如何学运维on Not Found/etc... error. At the port level, this could be anything from network is unusable to network not found, etc...
I do NOT need to see every TCP packet flowing across the network but I do need to know about TCP/Port/WinSock (whichever works) events flowing across all ports.
Ideally, I would avoid WinPCAP as this is a distributable software product and people tend to dislike WinPCAP on their computers.
I am using .NET 4.0 Full - can somebody please point me in the right direction?
If you are not interested in seeing the actual TCP packets but only interested in the open connections why not use NETSTAT -a
?
It will provide you with the protocol, local, foreign and state information of the current connections on your clients computer.
Use the Process
class to spawn NETSTAT -a
. Redirect the output using Process.StandardOutput
to your application and then filter out the necessary strings with regex
or string.split
.
Thank you for your response - it led me to IPGlobalPrperties - http://www.eggheadcafe.com/sample-code/csharp.NET/c51bd463-c6c3-48fb-a972-5b440215992a/provides-information-about-the-transmission-control-protocol-tcp-connections-on-the-local-computer.aspx
Using a derivative of that code, I was able to set up a monitor for TCP events.
精彩评论