Disable network adapters or block all tcp connections

I was wondering if .NET could be used to disable a particular network interface, or alternatively, discard all existing TCP connections (from the whole system) and then block further creation.

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

From my understanding, monitoring NIC throughput from .NET is pretty straightforward. But I don't know if it is possible to block entire NICs or TCP connections.

Maybe with P / Invoke and WMI?

+2


source to share


1 answer


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

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

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

      



See if it should either solve your problem, or at least point you in the right direction.

+1


source







All Articles