2012-05-10 33 views
0

我试图过滤掉无线上的探头和广播帧。SharpPcap中的过滤器

使用SharpPcap。

((SharpPcap.AirPcap.AirPcapDevice)(device)).Filter = "wlan.fc.type eq 0"; 

不起作用

同样与

((SharpPcap.AirPcap.AirPcapDevice)(device)).Filter = "wlan.fc.type == 0"; 

此行似乎让广播

((SharpPcap.AirPcap.AirPcapDevice)(device)).Filter = "broadcast"; 

,但需要真正获得所有,上海管理框架。

+0

过滤器应该与tcpdump和wireshark使用的相匹配,以便您可以在那里测试过滤器,然后将它们与sharppcap一起使用。这些过滤器是否像wireshark一样按预期工作? –

+0

是的,他们在wireshark中工作100%,那是我从中获得过滤器的地方。 – Karl

+0

其他过滤器似乎没有任何东西,似乎开始wlan.fc等 – Karl

回答

0

我认为你的问题如下:Wireshark解码数据包,所以当你应用这些过滤器时,数据包已经被解码,因此能够访问wlan.fc.type字段。

根据我个人的经验和SharpPcap的使用情况,你试图使用的过滤器是用byte []来计算的,所以你需要更具体一些,以确保它的正确应用。

例如,我一直在使用这个过滤器来达到我的目的。

private const String filteringSV = "(ether[0:4] = 0x010CCD04)"; 

此外,请记住只在已打开的设备上设置过滤器。

if (nicToUse != null) 
     { 
      try 
      { 
       nicToUse.OnPacketArrival -= OnPackectArrivalLive; 
       nicToUse.OnPacketArrival += OnPackectArrivalLive; 
       try 
       { 
        if (nicToUse.Started) 
        nicToUse.StopCapture(); 
        if (nicToUse.Opened) 
        nicToUse.Close(); 
       } 
       catch (Exception) 
       { 
        //no handling, just do it. 
       } 

       nicToUse.Open(OpenFlags.Promiscuous|OpenFlags.MaxResponsiveness,10);     

       nicToUse.Filter = "(ether[0:4] = 0x010CCD04)"; 

       nicToUse.StartCapture(); 
      } 
      catch (Exception ex) 
      { 
       throw new Exception(Resources.SharpPCapPacketsProducer_Start_Error_while_starting_online_capture_, ex); 
      } 
     } 

希望它有帮助。