How to calculate a packet checksum without sending it?

Dima.Go picture Dima.Go · May 10, 2011 · Viewed 15.3k times · Source

I'm using scapy, and I want to create a packet and calculate its' checksum without sending it. Is there a way to do it?

Thanks.

Answer

Almog Cohen picture Almog Cohen · Jul 25, 2012

I've also tried to avoid show2() because it print the packet. I've found in the source a better solution:

del packet.chksum
packet = packet.__class__(bytes(packet))

This code regenerate the packet with the correct checksum without any print and actually is what show2() run in the background before printing.