这是我第一次使用SharpPcap库。
我使用VC# 2008创建了新项目,并将SharpPcap作为引用添加到我的项目中。我发布了一个示例代码来获取我的pc的接口,但我得到了这个错误:
错误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++;
}
}
}
}发布于 2010-02-06 13:45:20
您使用的是什么版本的SharpPcap?
我正在将一个小型的正在工作的项目从2.1.1迁移到2.4.1,并且库的某些部分已经发生了显著的变化。不久前我自己也遇到过这样的问题。
LivePcapDeviceList devices = LivePcapDeviceList.Instance;
foreach (LivePcapDevice device in devices)
{
// Do stuff here...
}发布于 2010-03-22 21:21:50
很抱歉对API进行了更改。我仍然在尝试正确地命名API。从v3.0开始,API变得相当干净,今后应该会更静态一些。如果你在devel列表或sf论坛上有任何问题,你会得到一个快速的回复。
克里斯·SharpPcap维护者/作者http://sharppcap.sf.net
发布于 2010-05-12 13:18:16
尝试使用Pcap.Net。它是用.NET编写的一个清晰的WinPcap包装器。
https://stackoverflow.com/questions/2189571
复制相似问题