mardi 26 juillet 2016

How to calculate a TCP packet checksum using Python?

I'm using Scapy (the below code) to capture the IP/TCP packets on network:

sniff(iface='ens33', prn=call_back, filter="ip and dst host 10.0.0.12", store=0)

def call_back(packet):
    ip_packet = packet['IP']
    tcp_packet = ip_packet['TCP']

When I got 'ip_packet', I need to change its source address to another one, and send it out.

How can I re-calculate its checksum in IP header and TCP header?

Aucun commentaire:

Enregistrer un commentaire