禁用 NIC 或阻止所有 tcp 连接
我想知道是否可以使用 .NET 禁用某个网络接口,或者作为替代方案,删除所有现有的 TCP 连接(来自整个系统),然后禁止进一步创建。
我问这个问题是因为我想编写一个小型 C# 实用程序来监视系统并在总体速度低于阈值时在一定时间内阻止网络(或至少 TCP 连接)。 然后我希望它在一定分钟后恢复连接。
据我了解,从 .NET 内部监控 NIC 吞吐量相当容易。 但我不知道是否可以阻止整个 NIC 或 TCP 连接。
也许使用 P/Invoke 和 WMI?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了这个:如何终止任何网络连接。有一个人写了一整个类来终止任何网络连接。它围绕着代码中来自 IP Helper 的这两个导入(MSDN 链接)API:
看看,它应该可以解决您的问题,或者至少为您指明正确的方向。
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:
Have a look, it should either solve your problem or at least point you in the right direction.