Capture packet data (as hex)

Feb 12, 2011 at 9:08 PM

How can I capture packet data as in the WPE PRO? Look at screen: http://img62.imageshack.us/img62/6352/packet.png

Coordinator
Feb 18, 2011 at 3:38 PM

Hi surename,

 

After you capture a packet, you can iterate over it's bytes (using for each or [] operator).

Converting bytes to a hex string is pretty easy, see http://stackoverflow.com/questions/623104/c-byte-to-hex-string

 

Boaz.

Feb 21, 2011 at 4:19 PM
Edited Feb 21, 2011 at 4:19 PM

MY NEW START WITH PCAP, please guide : After you capture a packet, you can iterate over it's bytes

Thank!

Coordinator
Feb 23, 2011 at 12:47 PM

Hi haonhien,

 

I'm not sure whether you've asked a question.

The simplest to iterate over a packet's bytes is using foreach.

 

Boaz.

Feb 24, 2011 at 1:46 AM
brickner wrote:

Hi haonhien,

 

I'm not sure whether you've asked a question.

The simplest to iterate over a packet's bytes is using foreach.

 

Boaz.


I tried to convert bytes of the IP paload with the following code

 

IpV4Datagram ip = packet.Ethernet.IpV4;

byte[] packetbyte = new byte[ip.Length];

 

 

 

for (int i = 0; i < ip.Payload.Length; i++)

packetbyte[i] = ip.Payload[i];

 

Console.WriteLine(System.Text.Encoding.ASCII.GetString(packetbyte));


But still not as expected

0000  33 33 00 00 00 0c 00 22  19 f0 57 fc 86 dd 60 00  

0010  00 00 00 9a 11 01 fe 80  00 00 00 00 00 00 28 c2  

0020  03 22 d6 45 f9 58 ff 02  00 00 00 00 00 00 00 00  

0030  00 00 00 00 00 0c dc 65  07 6c 00 9a f9 bd 4d 2d  

0040  53 45 41 52 43 48 20 2a  20 48 54 54 50 2f 31 2e  

0050  31 0d 0a 48 6f 73 74 3a  5b 46 46 30 32 3a 3a 43  

0060  5d 3a 31 39 30 30 0d 0a  53 54 3a 75 72 6e 3a 4d  

0070  69 63 72 6f 73 6f 66 74  20 57 69 6e 64 6f 77 73  

0080  20 50 65 65 72 20 4e 61  6d 65 20 52 65 73 6f 6c   

0090  75 74 69 6f 6e 20 50 72  6f 74 6f 63 6f 6c 3a 20  

00a0  56 34 3a 49 50 56 36 3a  4c 69 6e 6b 4c 6f 63 61  

00b0  6c 0d 0a 4d 61 6e 3a 22  73 73 64 70 3a 64 69 73  

00c0  63 6f 76 65 72 22 0d 0a  4d 58 3a 33 0d 0a 0d 0a

Coordinator
Feb 26, 2011 at 8:18 AM

If you want to display the packets as HEX you need to convert each byte to hex and not to ASCII.

 

There are plenty of ways to do this conversion, see http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa-in-c