// Callback function invoked by libpcap for every incoming packet private static void PacketHandler(Packet packet) { // print timestamp and length of the packet IpV4Datagram ip = packet.Ethernet.IpV4; String source = ip.Source.ToString(); // Chat service IP. if (source != "178.79.171.171") { return; } // get original layers var ethernet = (EthernetLayer)packet.Ethernet.ExtractLayer(); var ipV4 = (IpV4Layer)packet.Ethernet.IpV4.ExtractLayer(); var tcp = (TcpLayer)packet.Ethernet.IpV4.Tcp.ExtractLayer(); var http = (HttpLayer)packet.Ethernet.IpV4.Tcp.Http.ExtractLayer(); string ethString = packet.Ethernet.BytesSequenceToHexadecimalString("-"); string ipv4String = packet.Ethernet.IpV4.BytesSequenceToHexadecimalString("-"); string tcpString = packet.Ethernet.IpV4.Tcp.BytesSequenceToHexadecimalString("-"); string transportString = packet.Ethernet.Ip.Transport.BytesSequenceToHexadecimalString("-"); string httpString = packet.Ethernet.Ip.Tcp.Http.BytesSequenceToHexadecimalString("-"); if (http.Body == null) { return; } var time = packet.Timestamp; string transportHead = packet.Ethernet.Ip.Transport.Decode(Encoding.UTF8); string transportData = packet.Ethernet.Ip.Transport.Payload.Decode(Encoding.UTF8); string htmlHead = packet.Ethernet.Ip.Tcp.Http.Decode(Encoding.UTF8); string htmlData = packet.Ethernet.Ip.Tcp.Http.Body.Decode(Encoding.UTF8); byte[] bodyStream = packet.Ethernet.Ip.Tcp.Http.Body.ToArray(); byte[] decompressed = Decompress(bodyStream); byte[] httpBody = http.Body.ToArray(); string result = Unzip(httpBody); // extract the data PayloadLayer payload = (PayloadLayer)packet.Ethernet.IpV4.Tcp.Payload.ExtractLayer(); var totalLength = payload.Length; var buffer = new byte[totalLength]; ////payload.Write(buffer, 1, totalLength, ipV4, null); Datagram data = payload.Data; string someSHit = data.BytesSequenceToHexadecimalString("-"); string jsonStr = data.Decode(Encoding.ASCII); object jsonShit = JsonConvert.DeserializeObject <Dictionary <String, Object> >(jsonStr); System.Windows.Forms.MessageBox.Show("I'm here!!!"); }