views:

158

answers:

1

I was wondering if it's possible to use .NET to disable a certain network interface or, in alternative, to drop all the existing TCP connections (from the whole system) and then inhibit further creation.

I'm asking this because I want to write a small C# utility that monitors the system and blocks networking (or at least TCP connections) for a certain amount of time if the overall speed drops below a threshold. And then I'd want it to restore connectivity after a certain number of minutes.

From what I understand monitoring a NIC throughput from within .NET is fairly easy. But I don't know if it's possible to block a whole NIC or TCP connections.

Maybe with P/Invoke and WMI?

+1  A: 

I found this: How to kill any network connection. There is an entire class written by a guy to kill any network connection. It revolves around these two imports in your code from the IP Helper (MSDN Link) API:

[DllImport("iphlpapi.dll")] 
public static extern int GetTcpTable( ... ); 

[DllImport("iphlpapi.dll")] 
public static extern int SetTcpEntry( ... );

Have a look, it should either solve your problem or at least point you in the right direction.

Mr. Smith
Thanks, I suppose directly using the WIN32 API is the way to go to achieve what I want.I've never done it before but it doesn't seem too difficult.Fortunately there's a good reference at MSDN.
RobSullivan