Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use the code below to show informations about the incoming tcp packet
C#
private static void device_OnPacketArrival(object sender, CaptureEventArgs e)
        {
            var time = e.Packet.Timeval.Date;
            var len = e.Packet.Data.Length;
            Console.WriteLine("{0}:{1}:{2},{3} Len={4}",
               time.Hour, time.Minute, time.Second, time.Millisecond, len);
            Console.WriteLine(e.Packet.ToString());                     
         }


This code works fine, but now i want to get the packet in the packet, if there is one, using this code:
C#
Packet p = PacketDotNet.Packet.ParsePacket(e.Packet.LinkLayerType,  e.Packet.Data); 
var tcp = (TcpPacket)p.Extract(typeof(TcpPacket));
    if (tcp.PayloadPacket != null)
          Console.WriteLine(tcp.PayloadPacket.PayloadData.ToString());

and with this code the if reference always become false..
I also want to convert the html request in string format to show the requested url in the console (if the packet contains one).

Hope you can help me or give me a (complete) description link for SharpPcap, especially the Packet.Payload and converting part.
Posted
Updated 22-Mar-15 8:04am
v2
Comments
SubbZer 8-Apr-15 8:21am    
I found a project on myCSharp.de which also contains the source code.
The program reads the html/tcp traffic on your networkcard using WinPcap.
Link: http://www.mycsharp.de/wbb2/thread.php?threadid=74918&hilight=httpsaver
Note: The program doesnt work on my PC but it contains the html translation and the capture events which should work.

I have done some troubleshooting and i found some tcp packets which always contains a null reference.
This ones are outgoing packets, so i asked myself, does WinPcap get the outgoing packages before they get payloaded in tcp format or somthing else?
The incomming http packages are certainly in tcp format, but which format has the outgoing packet?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900