def is_pcap(pcap):
    """
    Simple test for pcap magic bytes in supplied file.

    :param pcap: File path to Pcap file to check
    :returns: True if content is pcap (magic bytes present), otherwise False.
    """
    with open(pcap, 'rb') as tmp:
        header = tmp.read(4)
        # check for both big/little endian
        if header == b"\xa1\xb2\xc3\xd4" or \
           header == b"\xd4\xc3\xb2\xa1":
            return True
        return False
def is_pcap ( pcap ) : with open ( pcap , 'rb' ) as tmp : header = tmp . read ( 4 ) if header == b"\xa1\xb2\xc3\xd4" or header == b"\xd4\xc3\xb2\xa1" : return True return False
Simple test for pcap magic bytes in supplied file.

    :param pcap: File path to Pcap file to check
    :returns: True if content is pcap (magic bytes present), otherwise False.