1

这是我第一次使用 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++;
            }
        }
    }
}
4

3 回答 3

5

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

我正在将一个小型正在进行的项目从 2.1.1 移动到 2.4.1,并且库的某些部分发生了显着变化。就在不久前,我自己也在为此苦苦挣扎。

LivePcapDeviceList devices = LivePcapDeviceList.Instance;
    foreach (LivePcapDevice device in devices)
    {
         // Do stuff here...
    }
于 2010-02-06T05:45:19.660 回答
4

对 API 更改感到抱歉。我仍在尝试正确命名 API。从 v3.0 开始,API 变得更加简洁,并且在未来应该更加静态。如果您在开发列表或 sf 论坛上发布任何问题,您将得到快速回复。

Chris SharpPcap 维护者/作者 http://sharppcap.sf.net

于 2010-03-22T13:21:50.223 回答
-1

尝试使用Pcap.Net。它是 .NET 中的一个清晰的 WinPcap 包装器。

于 2010-05-12T05:18:16.190 回答