-2

I tried to write sniffer in C# and in Google I found this tutorial. I added to class TCPHeader

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

To see messages received, but I can see only sent packets. How should I modify it to see received data too?

L.B
  • 114,136
  • 19
  • 178
  • 224
ThisGuy
  • 5
  • 1
  • 3
    search for another tutorial? (btw, the code you posted is not really relevant to your question) – Vlad Nov 01 '12 at 12:42

2 Answers2

0

You can inplement a sniffer based on fiddler core library , I think it's better choice. Thanks

FiddlerCore - Fiddler Proxy Engine for your .NET Applications www.fiddler2.com/core/

StringBuilder
  • 1,619
  • 4
  • 32
  • 52
0

I have met the same problem and finally find out that it is the Windows firewall that block you from sniff incoming package. After turning off windows firewall, it will work. In Win10, you can turn it off in control panel, or use command netsh advfirewall set allprofiles state off or use c# code like this

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();
}

Please notice that I only test it on win10, in other system, the command may be a bit different.

Xiangyu.Wu
  • 459
  • 1
  • 5
  • 18