Visual Studio 2010中配置SharpPcap

一.我的编程环境:

 

     win7旗舰版 、VS2010旗舰版、WinPcap4.1.3、SharpPcap4.2.0。

 

二. 安装及调试步骤:

 

    1.安装Winpcap4.1.3(WinPcap4.1.3下载)

 

    2.解压SharpPcap-4.2.0.bin.zip(SharpPcap4.2.0.bin.zip&&SharpPcap4.2.0.src.zip下载)解压后打开debug文件夹,可以看到里面有两个dll文件,这就是我们程序中要用到的东西。SharpPcap-4.2.0.src.zip压缩包中,包含SharpPcap的所有源代码和一些示例程序。

 

    3.打开VS2010,新建一个C#的控制台项目。

 

    4.然后单击“项目”下拉菜单,选择 “添加引用”,在弹出的对话框中单击 “浏览” 选项卡,然后选择第2步中SharpPcap-4.2.0.bin.zip解压后的路径,然后将debug中的SharpPcap.dll添加进去。

 

    5.将下面的代码,粘贴到你的项目中,测试配置是否成功,如果成功则会显示你的网络适配器的信息。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using SharpPcap;
 6 
 7 namespace SharpPcap1
 8 {
 9     class Program
10     {
11         public class IfListAdv
12         {
13             /// <summary>
14             /// Obtaining the device list
15             /// </summary>
16             public static void Main(string[] args)
17             {
18                 // Print SharpPcap version
19                 string ver = SharpPcap.Version.VersionString;
20                 Console.WriteLine("SharpPcap {0}, Example1.IfList.cs", ver);
21 
22                 // Retrieve the device list
23                 var devices = CaptureDeviceList.Instance;
24 
25                 // If no devices were found print an error
26                 if (devices.Count < 1)
27                 {
28                     Console.WriteLine("No devices were found on this machine");
29                     return;
30                 }
31 
32                 Console.WriteLine("\nThe following devices are available on this machine:");
33                 Console.WriteLine("----------------------------------------------------\n");
34 
35                 /* Scan the list printing every entry */
36                 foreach (var dev in devices)
37                     Console.WriteLine("{0}\n", dev.ToString());
38 
39                 Console.Write("Hit 'Enter' to exit...");
40                 Console.ReadLine();
41             }
42         }
43     }
44 }

如果配置无误的话,编译运行这段代码会得到如下的结果:

 

 

转载于:https://www.cnblogs.com/lonlex/p/3667996.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值