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....

4

2 回答 2

1

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

于 2011-03-27T11:41:28.583 回答
0

Have a look at the PyIP module.

于 2011-03-27T09:21:04.980 回答