Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
{
   }
Posted
Updated 19-Feb-17 4:34am
v3

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
 
Share this answer
 
Comments
NoorKaximi 19-Feb-17 15:47pm    
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\StandardCimv2",
"SELECT * FROM MSFT_NetAdapter");

foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Name: {0}", queryObj["Name"]);

Console.WriteLine("PromiscuousMode: {0}", queryObj["PromiscuousMode"]);

}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
I tried the above code but it is not working it return promiscuous mode false although i have enabled it using wireshark. Wireshark show promiscuous mode is enabled but wmi query return false for promiscuous mode
You can use WMI to get the MAC adress(es), see this post:
C# Get Computer's MAC address "OFFLINE" - Stack Overflow[^]
 
Share this answer
 
Comments
NoorKaximi 19-Feb-17 6:31am    
i don't need MAC Address
I want to detect the promiscuous mode of network interface. Kindly read complete question.
Ralf Meier 19-Feb-17 6:39am    
What do you mean with "promiscuous mode" ?
There are a lot of possible translations for this word with different sense ...
NoorKaximi 19-Feb-17 6:41am    
In computer networking, promiscuous mode (often shortened to "promisc mode" or "promisc. mode") is a mode for a wired network interface controller (NIC) or wireless network interface controller (WNIC) that causes the controller to pass all traffic it receives to the central processing unit (CPU) rather than passing only the frames that the controller is intended to receive.
Ralf Meier 19-Feb-17 6:46am    
OK ... I understand ...
What I suggest would be :
create a Timer with a cyclic Method-call or a BackgroundWorker or a Thread.
In this method you check this interface and give the result back with for example a public Variable.
NoorKaximi 19-Feb-17 6:48am    
i just want to check whether promiscuous mode is enabled or not on my PC.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900