Randomizing IPv4 Address

49 views
Skip to first unread message

Sandeep Kappala

unread,
May 16, 2015, 4:17:16 AM5/16/15
to pcapd...@googlegroups.com, v_sa...@yahoo.co.in
Hello,

I am working on network trace randomization using offline pcap dump file.
I am trying to randomize the IPv4 address inside the packets. I am able to do the randomization. Now i am working on doing the randomization by preserving the prefix of the ip address. In other words, after i finish the randomization i should be able to tell, which all ip addresses belong to the same network.

Please let me know if there is any built in function in PCap.net to preserve the prefix of IPv4 address. It would be helpful ifs someone can help it out with this logic.

Thanks in advance for your help.

Regards,
Sandeep

Boaz Brickner

unread,
May 16, 2015, 6:55:44 AM5/16/15
to pcapd...@googlegroups.com, v_sa...@yahoo.co.in
Hi Sandeep,

There's no built in capability for masking IPv4 addresses.
You can simply create an IPv4 address mask and use IpV4Address.ToValue() to convert it to a UInt and then use bitwise operations.

I hope this helps,

Boaz.

deep.s...@gmail.com

unread,
May 16, 2015, 7:27:24 AM5/16/15
to pcapd...@googlegroups.com, v_sa...@yahoo.co.in
Hi Boaz,

Thank you for your response. I have to randomize the address in the entire pcap file. So how do i get the mask for all the addresses present in the dump file.
eg: let's assume there are 3 addresses A,B and C in the initial pcap file. A and c belong to one subnetwork. After the randomization it is mapped as A1, B1 and C1. and still A1 and C1 should belong to one subnetwork. Not necessarily the original subnet.

I am not sure how to explain my question clearly. I hope i didn't confuse you.

Regards,
Sandeep

Boaz Brickner

unread,
Jun 13, 2015, 1:44:24 AM6/13/15
to pcapd...@googlegroups.com, v_sa...@yahoo.co.in
Hi Sandeep,

Probably a proper example would help.
For example, if you have
A=1.2.3.4
And you want to create
B=1.2.random1.random2

You can do (maybe some casting to uint would be required)
B = new IpV4Address((GetRandomUInt() & 0x0000FFFF) | (A.ToValue() & 0xFFFF0000));

Makes sense?
Boaz.
Reply all
Reply to author
Forward
0 new messages