如何在C#中检测混杂的网络接口模式? [英] How to detect promiscuous mode of network interface in C#?

查看:128
本文介绍了如何在C#中检测混杂的网络接口模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个应用程序来检测网络接口是否处于混杂模式。

我们可以通过发送错误的MAC地址但是IP地址错误的ping(ICMP回应请求)来检测它。如果适配器在正常模式下运行,它将丢弃此帧,并且IP堆栈永远不会看到或响应它。如果适配器处于混杂模式,则帧将被传递,并且机器上的IP堆栈(MAC地址没有任何意义)将像对任何其他ping一样响应。

但我不知道如何在c#中实现它。



我尝试过:



我试过这个代码,但它给了我任何特定IP地址的mac地址。



 if(SendArp( ip,0,macAddr,ref macAddrLen)!= 0)
{
return false;
}
其他
{
}

解决方案

From < a href =http://stackoverflow.com/questions/42327012/how-to-detect-promiscuous-mode-of-network-interface-in-c> StackOverflow [ ^ ]

Quote:



使用System.Management进行此类查询。 MSFT_NetAdapter类,PromiscuousMode属性。使用WMI代码创建器进行实验并获得正确的C#代码。 - Hans Passant


您可以使用 WMI 来获取MAC地址,请参阅此帖子:

C#获取计算机的MAC地址离线 - Stack Overflow [ ^

I am building an application to detect whether the network interface is in promiscuous mode or not.
We can detect it by sending a ping (ICMP echo request) with the wrong MAC address but the right IP address. If an adapter is operating in normal mode, it will drop this frame, and the IP stack never sees or responds to it. If the adapter is in promiscuous mode, the frame will be passed on, and the IP stack on the machine (to which a MAC address has no meaning) will respond as it would to any other ping.
But I don't know how to implement it in c#.

What I have tried:

I have tried this code but it gives me mac address for any particular ip address.

if (SendArp(ip, 0, macAddr, ref macAddrLen) != 0)
{
    return false;
}
else
{
   }

解决方案

From StackOverflow[^]

Quote:


Use System.Management for such kind of queries. MSFT_NetAdapter class, PromiscuousMode property. Use WMI Code Creator to experiment and arrive at the correct C# code. – Hans Passant


You can use WMI to get the MAC adress(es), see this post:
C# Get Computer's MAC address "OFFLINE" - Stack Overflow[^]


这篇关于如何在C#中检测混杂的网络接口模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆