tags:

views:

267

answers:

3

This is my first time to use SharpPcap library.

I created new project with VC# 2008 and I added SharpPcap as a reference to my project. I post a sample code to get interface of my pc but I'm getting this error:

Error 1 The type or namespace name 'PcapDeviceList' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Ali\Documents\Visual Studio 2008\Projects\Pcap\Pcap\Form1.cs 28 13 Pcap

please advice to solve this problem.

here is my code:

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++;
            }
        }
    }
}
+1  A: 

What version of SharpPcap are you using?

I'm moving a small in-work project from 2.1.1 to 2.4.1, and parts of the library have changed significantly. I struggled with this myself just a bit ago.

LivePcapDeviceList devices = LivePcapDeviceList.Instance;
    foreach (LivePcapDevice device in devices)
    {
         // Do stuff here...
    }
mbmcavoy
A: 

Sorry about the API changes. I'm still trying to get the API named properly. As of v3.0 the API is considerably cleaner and should be a bit more static going forward. If you have any trouble post on the devel list or sf forums and you'll get a quick reply.

Chris SharpPcap maintainer/author http://sharppcap.sf.net

Chris Morgan
A: 

Try using Pcap.Net. It's a clear WinPcap wrapper in .NET.

brickner