How to get the data from TcpPacket in a readable format using SharpPcap?

2.1k Views Asked by At

I am building sniffer for my final year project.I want to extract the data from TCP in a human readable format.

I am getting the data in Hex format using BitConverter but i want data to be readable i.e. all the Http Browsed links,Get requests,Post requests and other data in the output. Here is my code:

while((packet = device.GetNextPacket()) != null)
{
   var pack = PacketDotNet.Packet.ParsePacket(packet.LinkLayerType, packet.Data);
   var tcp = TcpPacket.GetEncapsulated(pack);
   if(tcp != null)
   {
      var sp = tcp.SourcePort;
      var dp = tcp.DestinationPort;
      var data = BitConverter.ToString(tcp.PayloadData);
      Console.WriteLine("{0}:{1}:{2}",sp,dp,data);
   }
}

Please help, i have less time and searched a lot but unable to get anything..

Thanks in advance

1

There are 1 best solutions below

0
On

you can use next:

var data = Encoding.Unicode.GetString(tcp.PayloadData);