2012-11-01 58 views
-2

我試圖在C#和Google中編寫嗅探器,我發現this教程。我添加到類TCPHeaderC#嗅探器 - 收到的數據

string wiad = Encoding.UTF8.GetString(byTCPData); 
if (wiad.Contains("|")) 
    MessageBox.Show(wiad); 

要查看收到的消息,但我只能看到發送的數據包。我應該如何修改它以查看收到的數據呢?

+3

尋找另一個教程? (順便說一下,你發佈的代碼與你的問題並不相關) – Vlad

回答

0

你可以實現基於fiddler核心庫的嗅探器,我認爲這是更好的選擇。由於

FiddlerCore - 提琴手代理引擎www.fiddler2.com/core/

0

我遇到過同樣的問題,終於發現這是禁止您嗅傳入包中的Windows防火牆你的.NET應用程序。關閉Windows防火牆後,它將工作。 在Win10,你可以關閉它在控制面板中,或者使用命令 netsh advfirewall set allprofiles state off 或使用C#這樣的代碼

public static void TurnOffFireWall() 
{ 
    // Have only been tested in Win10 
    Process proc = new Process(); 
    string top = "netsh.exe"; 
    proc.StartInfo.Arguments = "advfirewall set allprofiles state off"; 
    proc.StartInfo.FileName = top; 
    proc.StartInfo.UseShellExecute = false; 
    proc.StartInfo.RedirectStandardOutput = true; 
    proc.StartInfo.CreateNoWindow = true; 
    proc.Start(); 
    proc.WaitForExit(); 
} 

請注意,我只測試它在win10,在其他系統中,該命令可能有點不同。