2023 m. vasario 15 d., trečiadienis

python structs and bytes

Comprehensive video about str and bytes

Script to get ICMP packet data:

https://gist.github.com/Paulius11/a49d9c8443d7477bb546f85c4a098d9f

Working with TCP/IP protocol stack:

 

Ethernet Frame Format 

 

eth_header=struct.unpack('!6s6sH', data)

 

 ICMP headers
https://th.bing.com/th/id/R.896fd1f80906bc6b76fb37ab508b1019?rik=%2bzHw3WcocYKhog&riu=http%3a%2f%2fwww.techbooksforfree.com%2fintro_to_data_com%2fstdimages%2fpage247.gif&ehk=IFqgBioiyL47m1UlVNpWIRL0c7nfPCFFBtS2%2bwrMdSU%3d&risl=&pid=ImgRaw&r=0
Internet Protocol Header

Internet Protocol header struct - !BBHHHBBH4s4s
   


# s    char[]    bytes

# H (unsigned short) Integer  = 2 (standard octets)

# B Integer  = 1 (standard octets)

eth_header=struct.unpack('!6s6sH', data)

icmp_type, code, checksum, packet_id, sequence = struct.unpack('!BBHHH', packet[20:28])

https://www.binarytides.com/python-packet-sniffer-code-linux/ -

https://www.bitforestinfo.com/blog/02/15/how-to-write-simple-packet-sniffer.html