0

I use PcapDotnet wrapper for sniff packets but it show just ip raw packets for example at clientside i send that packet

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

and at serverside i want to capture "test" but packet.Buffer show different 66 bytes.Can i get just "test" packets ?

  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);
        }
    }
Burak Dincer
  • 65
  • 1
  • 9

1 Answers1

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

is printing ALL the binary, including the IPv4 header and the TCP header.

try just:

File.AppendAllText("return.txt", ASCIIEncoding.ASCII.GetString(tcp.Payload??));
divinci
  • 22,329
  • 11
  • 45
  • 56
  • i used packetDotNet wrapper and i received correct packets with PayLoad ((packet.PayloadPacket).PayloadPacket).PayloadData, – Burak Dincer Apr 16 '15 at 11:01