2015-02-08 117 views
0

我用PcapDotnet包裝器嗅探數據包,但它只顯示IP原始數據包 例如在客戶方我發送一個數據包的Tcp原始數據包

client_.Send(ASCIIEncoding.ASCII.GetBytes("test")); 

,並在服務器端,我想捕捉「測試」,但packet.Buffer顯示不同的66個字節。我可以得到「測試」數據包嗎?

private static void PacketHandler(Packet packet) 
    { 
     IpV4Datagram ip = packet.Ethernet.IpV4; 
     TcpDatagram tcp = ip.Tcp; 

     if (tcp.DestinationPort == 28001 || tcp.SourcePort == 28001) 
     { 
      File.AppendAllText("return.txt", ASCIIEncoding.ASCII.GetString(packet.Buffer)); 
      Console.WriteLine(ip.Source + ":" + tcp.SourcePort + " -> " + ip.Destination + ":" + tcp.DestinationPort); 
     } 
    } 

回答

1
File.AppendAllText("return.txt", ASCIIEncoding.ASCII.GetString(packet.Buffer)); 

正在打印所有二進制,包括IPv4標頭和TCP報頭。

嘗試只:

File.AppendAllText("return.txt", ASCIIEncoding.ASCII.GetString(tcp.Payload??)); 
+0

我用packetDotNet包裝並且收到了有效載荷 正確的數據包((packet.PayloadPacket).PayloadPacket).PayloadData, – 2015-04-16 11:01:08