簡體   English   中英

SharpPcap中的過濾器

[英]Filters in SharpPcap

我試圖過濾掉他在wifi上的探測和廣播幀。

使用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";

但需要真正獲得所有代理框架。

我認為您的問題如下: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);
            }
         }

希望能有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM