from impacket import LOG from impacket.ImpactPacket import * from impacket.ImpactDecoder import * # Create a packet sniffer sniffer = EthSniff() try: # Start logging to a file LOG.start(filename='packets.log') # Set up the sniffer and capture 5 TCP packets sniffer.start() packets = [] while len(packets) < 5: packet = sniffer.readPacket() if packet.getIP() and packet.getIP().getProtocol() == IPPROTO_TCP: packets.append(packet) # Print the packet contents and decode them for packet in packets: print(packet) decoder = EthDecoder() decoded_packet = decoder.decode(packet.getRawPacket()) print(decoded_packet) finally: # Stop logging and close the sniffer LOG.stop() sniffer.stop()In this example, we import the LOG module from Impacket and start logging to a file called 'packets.log'. We then create a packet sniffer using the EthSniff() class from Impacket. We set up the sniffer to capture 5 TCP packets and store them in a list. We then print the contents of each packet and decode them using the EthDecoder() class from Impacket. Finally, we stop logging and close the sniffer. The package library for Impacket is 'impacket'.