Sakir saiyed
Sakir saiyed

Reputation: 742

How to use Python to extract packet information from hexdump?

I am working on a network project where I have hexdump of packets and I need to dissect that hexdump packet to display all the packet information.

Example : Packet Information Fields -

source address
destination address
encapsulation type
frame number
frame length
FCS
data
epoch time

We are not supposed to use file as input and output because it will increase memory utilization and might crash server.

I tried with below code but this doesn't work in my case:

# imports scapy Utility

from scapy.all import *
from scapy.utils import *

# variable to store hexdump

hexdump = '0000  49 47 87 95 4a 30 9e 9c f7 09 70 7f....'

# Initialize a 802.11 structure from raw bytes

packet = Dot11(bytearray.fromhex(hexdump))

#scapy function to view the info

packet.summary()
packet.show()

Are there any suggestions to achieve this as I am new to this technology? I might lack some proper directions to solve this.

Upvotes: 1

Views: 2945

Answers (1)

Pierre
Pierre

Reputation: 6237

Your hexdump value seem to include the index. Remove it:

  • On Scapy >= 2.4rc:

    data = hex_bytes('49 47 87 95 4a 30 9e 9c f7 09 70 7f [...]'.replace(' ', ''))
    
  • Or with Python 2 and Scapy <= 2.3.3:

    data = '49 47 87 95 4a 30 9e 9c f7 09 70 7f [...]'.replace(' ', '').decode('hex')
    

Then:

Dot11(data)

Upvotes: 2

Related Questions