0

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?

cnicutar
  • 178,505
  • 25
  • 365
  • 392
Cloud Ruan
  • 11
  • 5

1 Answers1

0

Scapy will do that for you, provided you remove the existing value:

def call_back(packet):
    del packet[IP].chksum, packet[TCP].chksum
    packet[IP].src = "1.2.3.4"
    sendp(packet)

If packet does not include an Ether() layer and starts directly with the IP() layer, replace sendp() by send().

Pierre
  • 6,047
  • 1
  • 30
  • 49