0

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 IPHeader

Please tell how should i proceed....

2 Answers 2

1

Scapy can create IP headers easily.
Here they have an example on creating IP header.

Sign up to request clarification or add additional context in comments.

Comments

0

Have a look at the PyIP module.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.