I’m writing my first program in Python.
I’m using a third-party kit for interacting with network packets (Scapy).
When I use this method:
p=sr1(IP(dst="google.com")/TCP())
the result is:
<IP version=4L ihl=5L tos=0x0 len=44 id=18972 flags= frag=0L ttl=44
proto=tcp chksum=0x25bd src=173.194.39.134 dst=192.168.137.2
options=[] |<TCP sport=www dport=ftp_data seq=1295300429 ack=1
dataofs=6L reserved=0L flags=SA window=14300 chksum=0x3c7e urgptr=0
options=[('MSS', 1430)] |<Padding load='\x00\x00' |>>>
I can access to chksum of IP simply by p.chksum, but how can I access to chksum of TCP?
As a general guideline, you should use
However this only works for received packets because the checksum is calculated on transmit. You can retrieve the checksum for an untransmitted packet with the show2() method.