2012-05-10 32 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); 
      } 
     } 

希望它有幫助。