日期:2014-05-18  浏览次数:21061 次

为什么我写的这些 没效果?关于SharpPcap的问题
如题,我根据SharpPcap写了一个 监视封包的 类 但是为什么 调用 Run方法后OnPacketArrival事件的处理函数就是收不到一个数据呢?真的是很奇怪啊。。。为什么呢?也不报错。。。就是没反映(不是程序挂死,只是收不到任何的数据)查了很久就是没结果,难道是SharpPcap的内部错误,我想应该不会吧。。。。
请高手给我看一下。。。

C# code
 public class Device:IDisposable
    { 
        public Device()
        {
            //.Devices(System.Net.IPAddress.Any, 0, new Win.RemoteAuthentication(Win.AuthenticationTypes.Null, "", ""));
          

        }


        public void Run(SharpPcap.PacketArrivalEventHandler packetArrival,string filter)
        {
            
            OriDevice = OriDevices[1];
            if (filter == string.Empty)
            {
                filter = "ip and tcp";
            }
            OriDevice.OnPacketArrival += new PacketArrivalEventHandler(packetArrival);//设置异步拦截事件
            OriDevice.OnPacketArrival += new PacketArrivalEventHandler(OriDevice_OnPacketArrival);
            OriDevice.Open(SharpPcap.DeviceMode.Promiscuous,0);//打开设备
            OriDevice.Filter = filter;//设置拦截过滤器
            OriDevice.Mode = CaptureMode.Packets;
            //OriDevice.LinkType 
            OriDevice.StartCapture();//开始拦截
            //OriDevice.StopCapture();//开始拦截
            //OriDevice.Close();
        
        }

        void OriDevice_OnPacketArrival(object sender, CaptureEventArgs e)
        {
            System.Diagnostics.Debug.Write("OK");
        }
        public WinPcapDeviceList OriDevices { get { return WinPcapDeviceList.Instance; } }


        public void Stop()
        {
            if(OriDevice!=null)
            OriDevice.StopCapture();
        }


        public void Close()
        {
            if (OriDevice != null)
            {
                OriDevice.StopCapture();
                OriDevice.Close();
            }
        }






        public WinPcapDevice OriDevice { get; set; }

        #region IDisposable 成员

        public void Dispose()
        {
            Close();
            OriDevice = null;
        }


------解决方案--------------------
WinPcap有没有安装?