I am trying to print information about each protocol specifically:
conn = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)`
HOST = socket.gethostbyname(socket.gethostname())
# create a raw socket and bind it to the public interface
conn.bind((HOST, 0))
# Include IP headers
conn.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
# receives all packets
conn.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
try:
while True:
raw_data, addr = conn.recvfrom(65536)
print("Raw data received:", raw_data)
dest_mac, src_mac, eth_proto, data = ethernet_frame(raw_data)
print('\nEthernet Frame:')
print(TAB_1 + 'Destination: {}, Source: {}, Protocol: {}'.format(dest_mac, src_mac, eth_proto))
if eth_proto == 0x0800:
ipv4_info = ipv4_packet(data)
print(TAB_1 + 'IPv4 Packet:')
print(ipv4_info)
if proto == 1:
icmp_details = icmp_packet(data)
print(TAB_1 + 'ICMP Packet:')
print(icmp_details)
elif proto == 6:
tcp_info = tcp_segment(data)
print(TAB_1 + 'TCP Segment:')
print(tcp_info)
elif proto == 17:
udp_details = udp_segment(data)
print(TAB_1 + 'UDP Segment:')
print(udp_details)
But, it only shows me source, destination, protocol no : 43200 and data, and no other fields.
What necessary changes should I make?