2009-06-10 112 views
1

您好,我正在使用C#的窗口應用程序的工作, 我想知道如何監視網絡活動或網站的計算機活動..監控互聯網活動?

回答

3

你可能想看看「包嗅探」工具,例如EtherealTCPDump - 它們是開源的,並有命令行界面,因此您可以從程序中調用這些程序並分析它可能生成的任何日誌文件。數據包嗅探器掃描您的網絡以查找發送的數據包,互聯網活動通常會調用TCP和IP數據包,以便您可以過濾這些數據包並查看它們從哪裏發往哪裏。

+0

嗯,我們在2006年將Ethereal的名稱改爲Wireshark(http://www.wireshark.org)... – 2009-06-14 00:10:53

2

我想說你應該看看System.Diagnostics.PerformanceCounter類。該類別爲MSDN page

這是一小段代碼片斷,它提取網絡接口每秒的字節數。

PerformanceCounterCategory category = new PerformanceCounterCategory("Network Interface"); 

// Look at GetInstanceNames() result to find you interface, mine's 3 for example 
string instance = category.GetInstanceNames()[0]; 

PerformanceCounter sent = new PerformanceCounter("Network Interface", "Bytes Sent/sec", instance); 
PerformanceCounter received = new PerformanceCounter("Network Interface", "Bytes Received/sec", instance); 

while (true) 
{ 
    Console.WriteLine("Send {0}b/s\tReceive {1}b/s", sent.NextValue(), received.NextValue()); 
    Thread.Sleep(500); 
} 
3

你可以使用sharpPcap,這對.NET 數據包捕獲框架庫具有監視包了很多有用的功能, 可以過濾HTTP報文。