我正在尝试读取从客户端发送到服务器的数据包。但是,我收到一条错误消息:
无法加载dll“wpcap”:找不到指定的模块。(hresult的异常:0x8007007e)
有人能指出我怎样才能纠正这个错误吗?
我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpPcap;
using SharpPcap.AirPcap;
using PacketDotNet;

namespace ConsoleApplication2MB
{
    class Program
    {
        static void Main(string[] args)
        {
            //Extract the device list
            CaptureDeviceList devices = CaptureDeviceList.Instance;
            if (devices.Count < 1)
            {
                Console.WriteLine("No devices were found on this machine");
                return;
            }
            Console.WriteLine("\nThe following devices are available on this machine:");
            Console.WriteLine("----------------------------------------------------\n");

            Console.WriteLine("Available AirPcap devices:");
            for (var i = 0; i < devices.Count; i++)
            {
                Console.WriteLine("[{0}] - {1}", i, devices[i].ToString());
            }

            Console.WriteLine();
            Console.Write("Please choose a device to capture: ");
            var devIndex = int.Parse(Console.ReadLine());

            var device = devices[devIndex];
            device.Open(DeviceMode.Promiscuous);

            string filter = "ip and tcp";
            device.Filter = filter;

            device.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival);

            device.StartCapture();

            //Console.Write("Please press enter to exit...");
            //Console.ReadLine();
        }


        private static void device_OnPacketArrival(object sender, CaptureEventArgs e)
        {
            var time = e.Packet.Timeval.Date;
            var len = e.Packet.Data.Length;
            Console.WriteLine("{0}:{1}:{2},{3} Len={4}",
                    time.Hour, time.Minute, time.Second, time.Millisecond, len);
            Console.WriteLine(e.Packet.ToString());

            var packet = PacketDotNet.Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);

            var tcpPacket = PacketDotNet.TcpPacket.GetEncapsulated(packet);
            if (tcpPacket != null)
            {
                var ipPacket = (PacketDotNet.IpPacket)tcpPacket.ParentPacket;
                System.Net.IPAddress srcIp = ipPacket.SourceAddress;
                System.Net.IPAddress dstIp = ipPacket.DestinationAddress;
                int srcPort = tcpPacket.SourcePort;
                int dstPort = tcpPacket.DestinationPort;

                Console.WriteLine("{0}:{1}:{2},{3} Len={4} {5}:{6} -> {7}:{8}",
                        time.Hour, time.Minute, time.Second, time.Millisecond, len,
                        srcIp, srcPort, dstIp, dstPort);
            }



        }
    }
}

最佳答案

转到:http://www.winpcap.org/install/default.htm
下载并安装:Windows安装程序
重新运行应用程序。
没有更多:“无法加载dll'wpcap':找不到指定的模块。(hresult的异常:0x8007007e)

08-07 04:27