SharpPcap问题

Eyl*_*yla 1 c# sharppcap

这是我第一次使用SharpPcap库.

我用VC#2008创建了新项目,并添加了SharpPcap作为我项目的参考.我发布了一个示例代码来获取我的电脑的界面,但是我收到了这个错误:

错误1找不到类型或命名空间名称'PcapDeviceList'(您是否缺少using指令或程序集引用?)C:\ Users\Ali\Documents\Visual Studio 2008\Projects\Pcap\Pcap\Form1.cs 28 13 Pcap

请指教解决这个问题.

这是我的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SharpPcap;
using SharpPcap.Packets;
using SharpPcap.Protocols;
using SharpPcap.Util;


namespace Pcap
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            /* Retrieve the device list */
            PcapDeviceList devices = SharpPcap.GetAllDevices();

            /*If no device exists, print error */
            if (devices.Count < 1)
            {
                Console.WriteLine("No device found on this machine");
                return;
            }

            int i = 0;

            /* Scan the list printing every entry */
            foreach (PcapDevice dev in devices)
            {
                /* Description */
                label1.Text = "{0}) {1}" + i + dev.PcapDescription +"\n"+

                /* Name */
                "\tName:\t{0}" + dev.PcapName+"\n"+
                /* IP Address */
                "\tIP Address: \t\t{0}"+ dev.PcapIpAddress+"\n"+
                /* Is Loopback */
                "\tLoopback: \t\t{0}"+ dev.PcapLoopback;


                i++;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

mbm*_*voy 5

您使用的是什么版本的SharpPcap?

我正在将一个小型的工作项目从2.1.1移动到2.4.1,并且部分库已经发生了重大变化.不久前我自己也在努力解决这个问题.

LivePcapDeviceList devices = LivePcapDeviceList.Instance;
    foreach (LivePcapDevice device in devices)
    {
         // Do stuff here...
    }
Run Code Online (Sandbox Code Playgroud)