.Net 抓取網路流量資訊 .Net 抓取網路流量資訊
  .NET       ez      2012-06-04

利用 .Net 抓取電腦的網路流量,程式碼如下:

using System;
using System.Net.NetworkInformation;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
                IPGlobalStatistics ipstat = properties.GetIPv4GlobalStatistics();
                Console.Clear();
                Console.WriteLine("接收封包數:" + ipstat.ReceivedPackets);
                Console.WriteLine("轉發封包數:" + ipstat.ReceivedPacketsForwarded);
                Console.WriteLine("傳送封包數:" + ipstat.ReceivedPacketsDelivered);
                Console.WriteLine("丟棄封包數:" + ipstat.ReceivedPacketsDiscarded);
                System.Threading.Thread.Sleep(1000);
            }
        }
    }
}


標籤:   .NET

我要留言