[python]Understanding the fields of Ether and ARP in Scapy

To find out the fields of Ether
There is a ls method which can be used to show the fields of Ether.
e1
This ls method is used to find out the fields that i can put in values.
e2
This shows there are three fields, to send a broadcast frame, I need to put in ff:ff:ff:ff:ff:ff to the dst field.
There are two ways to do it.
First way is to create an Ether object, then pass in the broadcast value into dst like this:
e3
The show method will show the contents of the ethernet frame:
e4
As noticed from the output the src field is automatically filled in with my current interface mac address.

Another way is to directly put in the broadcast while creating the ether object.
scapy.all has a constant known as ETHER_BROADCAST which is the “ff:ff:ff:ff:ff:ff”.
e5
The result is the same:
e6

To find out fields of ARP
The method is the same for finding out the available fields for ARP.
e7
Which will give the below fields:
What we are interested to put value in is pdst which is the target ip address, if we are to query 192.168.1.10 then pdst will need to put in 192.168.1.10.

The method to fill in the pdst is the same as with Ether, so I can first create an ARP object, then put in the pdst later.
e9
which yields this result:
e10
As noticed, the hwsrc and the psrc are automatically filled with my interface’s ip address and mac address.

Another method is to directly create an ARP object with the pdst defined.
e11
Which yields the same result.
e12

Concatenate Ether and ARP
scapy.all uses “/” to concatenate Ether and ARP which is a division operator, it works though it is kind of weird in my opinion…
e13
The concatenated packet is:
e14

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s