import struct import ipaddress class IP_struct: def __init__(self, buff=None): header = struct.unpack('> 4 self.ihl = header[0] & 0x0F self.tos = header[1] self.len = header[2] self.id = header[3] self.offset = header[4] self.ttl = header[5] self.protocol_num = header[6] self.sum = header[7] self.src = header[8] self.dst = header[9] self.src_address = ipaddress.ip_address(self.src) self.dst_address = ipaddress.ip_address(self.dst) # map protocol constants to their names self.protocol_map = {1:"ICMP", 6:"TCP", 17: "UDP"} try: self.protocol = self.protocol_map[self.protocol_num] except Exception as e: print(f'{e} No known protocol for {self.protocol_num}') # ICMP response packet class ICMP_struct: def __init__(self, buff): header = struct.unpack('