Configure sharppcap in Visual Studio 2010

Source: Internet
Author: User
Tags visual studio 2010

Recently, I need to write a program under C # To capture ARP packets. I can find it online. in C #, I can only use sharppcap. Sharppcap is a re-encapsulated Winpcap with C #. For details, see the following link.

Sharppcap tutorial

I encountered some problems in the configuration process. Now I will write down the solutions to these problems so as not to forget about them and start Various painful debugging.

Let's take a look at my environment: win7 flagship edition, vs2010 flagship edition, winpcap4.1.3, and sharppcap4.2.0.

1. Install winpcap4.1.3 (download winpcap4.1.3)

2.decompress sharppcap-4.2.0.bin.zip(sharppcap4.2.0.bin.zip&sharppcap4.2.0.src.zip download) decompress the package and open the debug folder. You can see that there are two DLL files, which are what we need in our program. The SharpPcap-4.2.0.src.zip package contains all the source code for sharppcap and some sample programs.

3. Open vs2010 and create a C # console project.

4. click the "project" drop-down menu and select "add reference". In the displayed dialog box, click "Browse". Then, select the path after sharppcap-4.2.0.bin.zip is decompressed in step 2, and then decompress sharppcap in debug. DLL.

5. paste the following code into your project to test whether the configuration is successful. If the configuration is successful, your network adapter information is displayed.

using System;using System.Collections.Generic;using SharpPcap;namespace Example1{    /// <summary>    /// Obtaining the device list    /// </summary>    public class IfListAdv    {        /// <summary>        /// Obtaining the device list        /// </summary>        public static void Main(string[] args)        {            // Print SharpPcap version            string ver = SharpPcap.Version.VersionString;            Console.WriteLine("SharpPcap {0}, Example1.IfList.cs", ver);            // Retrieve the device list            var devices = CaptureDeviceList.Instance;            // If no devices were found print an error            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");            /* Scan the list printing every entry */            foreach(var dev in devices)                Console.WriteLine("{0}\n",dev.ToString());            Console.Write("Hit ‘Enter‘ to exit...");            Console.ReadLine();        }    }}

Notes:

1. If you want to use sharppcap3.5, set. NET Framework to 3.5 when you create a project (vs2010 defaults to 4.0). Otherwise, an error will occur during running.

2. If you are using a sharppcap DLL of a later version, you are advised not to use a later version when testing the sample program. Otherwise, errors may occur. During the test, the DLL uses sharppcap4.2 and the sample program uses sharppcap3.5. An error occurs during the generation.

Configure sharppcap in Visual Studio 2010

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.