shanky
shanky

Reputation: 41

scapy encoding when stringed

What is this encoding below that you get when you string a packet in scapy? This is certainly not hex.

str(IP()) ’E\x00\x00\x14\x00\x01\x00\x00@\x00|\xe7\x7f\x00\x00\x01\x7f\x00\x00\x01’

Upvotes: 4

Views: 4139

Answers (1)

Abdurahman
Abdurahman

Reputation: 658

the \x is the hex notation. In this case when you use str(IP()) you are trying to convert the packet data into string which is not completely valid because not every raw hex data could be found in ASCII table to substitute it with a letter so any hex that couldn't be converted will seen in this format \x14.

I think the following example will help:

  • viewing packet summary using scapy method
  • encoding the packet data into hex format to view using python methods

    Welcome to Scapy (2.1.1-dev)
    >>> pkt=IP()
    >>> pkt.summary()
    '127.0.0.1 > 127.0.0.1 ip'
    >>> data=str(pkt)
    >>> data.encode('hex')
    '450000140001000040007ce77f0000017f000001'
    >>>
    

consider these points:

  • in SCAPY if you create an IP layer without determining the source and destination the loopback address will be set as default for both as shown in the example '127.0.0.1 > 127.0.0.1 ip'
  • .summary() is a Scapy method
  • str(), .encode are a python methods

Upvotes: 4

Related Questions