This project is read-only.

How to calculate Internet Traffic without Local Traffic by

Jan 22, 2015 at 10:12 AM
I want to calculate internet Traffic and local traffic separately.

Can I do it by
Jan 28, 2015 at 3:41 PM
Edited Jan 28, 2015 at 3:42 PM
I want to get Total packets local Network and then reduced Total packets local Network of the total packets received.

How do i it?

I should check packet source ip and destination ip. but how?

Please help me???
Jan 30, 2015 at 8:33 AM
Hi am_s92,

Have you followed the Pcap.Net tutorial?

Can you better define what are you trying to do?
What are "packets local network"?

Jan 30, 2015 at 8:56 AM
Hi I want to calculate internet traffic.just Internet not LAN and internet

Packet local network means LAN packets, the packets that are on the local network.for example when to player are playing computer game under network.
Jan 30, 2015 at 9:35 AM
All internet packets you see are LAN packets, since they travel also through your LAN.
If you want to see packets that travel between your computer and a network outside your LAN, you should probably check the IP address of the packets and see if they are from or going to outside your network.
Jan 30, 2015 at 10:17 AM
Edited Jan 30, 2015 at 10:18 AM
Ok. How do I it? Can you give an example using pcap.Net for me?
Jan 30, 2015 at 11:03 AM
Please follow the Pcap.Net User Guide.
It contains plenty of examples and I believe you can start building something from there.
Jan 31, 2015 at 6:23 AM
Hi. I write The following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PcapDotNet.Core;
using PcapDotNet.Packets;
using System.Net;

namespace ConsoleApplication1
    class Program
        private static long internet = 0;
        private static long local;
        static void Main(string[] args)
            // Retrieve the device list from the local machine
            IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;

            if (allDevices.Count == 0)
                Console.WriteLine("No interfaces found! Make sure WinPcap is installed.");

            // Print the list
            for (int i = 0; i != allDevices.Count; ++i)
                LivePacketDevice device = allDevices[i];
                Console.Write((i + 1) + ". " + device.Name);
                foreach (var item in device.Addresses)
                    if(item.Address.Family == SocketAddressFamily.Internet)
                        Console.WriteLine("\n{0}\n -----------------------------------", item.Address.ToString());

            int deviceIndex = 0;
                Console.WriteLine("Enter the interface number (1-" + allDevices.Count + "):");
                string deviceIndexString = Console.ReadLine();
                if (!int.TryParse(deviceIndexString, out deviceIndex) ||
                    deviceIndex < 1 || deviceIndex > allDevices.Count)
                    deviceIndex = 0;
            } while (deviceIndex == 0);

            // Take the selected adapter
            PacketDevice selectedDevice = allDevices[deviceIndex - 1];
            // Open the device
            using (PacketCommunicator communicator =
                selectedDevice.Open(65536,                                  // portion of the packet to capture
                // 65536 guarantees that the whole packet will be captured on all the link layers
                                    PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
                                    1000))                                  // read timeout
                Console.WriteLine("Listening on " + selectedDevice.Description + "...");
                if (communicator.DataLink.Kind != DataLinkKind.Ethernet)
                    Console.WriteLine("This program works only on Ethernet networks.");
                // start the capture
                communicator.ReceivePackets(0, PacketHandler);

        // Callback function invoked by Pcap.Net for every incoming packet
        private static void PacketHandler(Packet packet)
            Console.WriteLine("Source: {0} destination: {1}", packet.Ethernet.Source.ToString(), packet.Ethernet.Destination.ToString());
but I don't know how check the IP address of the packets. Do "packet.Ethernet.Source" is the source ip address packets? it is IPV6?
Jan 31, 2015 at 2:17 PM
Hi am_s92,

As you can see in the Pcap.Net tutorial, reading the IPv4 source address and destination address is done by calling
There are similar properties for IpV6:
You can check whether the packet is IPv4 or IPv6 using
I hope this helps,

Jan 31, 2015 at 2:52 PM
Hi Brickner.

You help me. thank you.