2009-06-10 103 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报文。