Reputation:
For my larger project i need to start with creating a IPv4 network packet ( for simulation )
for the same I need to write a function that creates a header out of the passed data which has the source ip , dest ip and all the necessary fields
def convertIpv4( data ):
pass
For this I need you to guide me in the right direction.
Firstly I need to store the IP in 32 bits so for that if I have a string "192.168.2.1" what is the most efficient way to convert it into bytes and that too a size of 32 ??
Also if I create first a normal class with stuff like version = 4 and sourceip and dest ip then is there a way to convert it directly into a byte array with the position of objects just like the following header
Please tell how should i proceed....
Upvotes: 0
Views: 7301
Reputation: 10395
Scapy can create IP headers easily.
Here they have an example on creating IP header.
Upvotes: 1