Lab2
Lab2
Details
Aim: To provide an understanding of reading and filtering data packets using the
WinPcap packet capture drivers.
Outline
In this lab Visual Studio will be used to create a C#.NET application, which uses the
WinPcap packet capture drivers, to read and filter network traffic from a NIC on the local
machine.
Activities
Capturing Packets
If Visual Studio is installed on your machine, download the following solution to your
desktop:
http://www.dcs.napier.ac.uk/~cs342/CSN11102/WinPCap2.zip
Extract the WinPcap2 folder to the desktop, and open the C#.NET solution (.sln file). It
should contain the following which uses the SharpPcap wrapper code (Gal, 2010), for
the WinPcap packet capture drivers.
Change the network interface index number to the inbex of the Ethernet interface
found in the previous lab.
using System;
using Tamir.IPLib;
using Tamir.IPLib.Packets;
namespace NapierCapture
{
public class CapturePackets
{
public static void Main(string[] args)
{
// Get the list of NICs
PcapDeviceList NICList = SharpPcap.GetAllDevices();
Run the program, and test it by producing some network traffic. Verify that the
program is capturing packets. The output should look similar to the below.
Questions
WinPcap Filters
A powerful feature offered by WinPcap, is the capture filtering engine. This allows
traffic to be filtered using a filter string. Update the code with the filter shown in the
following code. In this case an “tcp” filter, so only packets containing tcp protocol
traffic will be captured.
Test the program, by generating some tcp traffic, such as loading a Web page, and
show that the program is capturing the data packets.
Questions
http://www.winpcap.org/docs/docs_40_2/html/group__language.html
Using the web page to research how to create a filter to only capture packets containing the
ICMP protocol.
Questions
Test the filter by generating some network traffic which should not containing the ICMP
protocol, and prove that the program DOES NOT capture the packets (such as web traffic).
Questions
Now test using ICMP traffic. The ping command line utility uses ICMP packets to test
connectivity to another system. Ping a neighbours PC on the local network, or ping a web
server on the internet, as shown below.
References
Gal, T. (2010, Jan). SharpPcap - A Packet Capture Framework for .NET. Retrieved Jan 2011, from
The Code Project: http://www.codeproject.com/KB/IP/sharppcap.aspx