utils/pcap_parser.py
def np_parse_pcap_worker(filename):
    """Parse a pcap file into a numpy matrix.
    Inputs:
      - filename : a pcap file that contains packets to parse

    Returns:
      - a numpy matrix where each row is a packet and each column is a
        different field
      - a numpy column array containing the corresponding time of each packet
    """

    pkts = rdpcap_raw(filename)
    design_mat = -1*np.ones((len(pkts), len(FEATURES)), dtype=int)
    time_arr = np.zeros((len(pkts), 1))
    count = 0
    for pkt_bytes, (sec, usec, wirelen, caplen) in pkts:
        time_arr[count] = float(sec) + float(usec)*1e-6
        ind = FEATURES.index('Ethernet_size')
        design_mat[count, ind] = wirelen
        pkt = parse_pkt(pkt_bytes)
        for header in pkt.keys():
            for field in pkt[header].keys():
                key = header + '_' + field
                ind = FEATURES.index(key)
                design_mat[count, ind] = pkt[header][field]
        count += 1
    return design_mat, time_arr
Parse a pcap file into a numpy matrix.
    Inputs:
      - filename : a pcap file that contains packets to parse

    Returns:
      - a numpy matrix where each row is a packet and each column is a
        different field
      - a numpy column array containing the corresponding time of each packet
    
Parse a pcap file into a numpy matrix.
Inputs:
filename : a pcap file that contains packets to parse
Parse a pcap file into a numpy matrix . Inputs : filename : a pcap file that contains packets to parse
def np_parse_pcap_worker(filename):
    pkts = rdpcap_raw(filename)
    design_mat = -1*np.ones((len(pkts), len(FEATURES)), dtype=int)
    time_arr = np.zeros((len(pkts), 1))
    count = 0
    for pkt_bytes, (sec, usec, wirelen, caplen) in pkts:
        time_arr[count] = float(sec) + float(usec)*1e-6
        ind = FEATURES.index('Ethernet_size')
        design_mat[count, ind] = wirelen
        pkt = parse_pkt(pkt_bytes)
        for header in pkt.keys():
            for field in pkt[header].keys():
                key = header + '_' + field
                ind = FEATURES.index(key)
                design_mat[count, ind] = pkt[header][field]
        count += 1
    return design_mat, time_arr
def np_parse_pcap_worker ( filename ) : pkts = rdpcap_raw ( filename ) design_mat = - 1 * np . ones ( ( len ( pkts ) , len ( FEATURES ) ) , dtype = int ) time_arr = np . zeros ( ( len ( pkts ) , 1 ) ) count = 0 for pkt_bytes , ( sec , usec , wirelen , caplen ) in pkts : time_arr [ count ] = float ( sec ) + float ( usec ) * 1e-6 ind = FEATURES . index ( 'Ethernet_size' ) design_mat [ count , ind ] = wirelen pkt = parse_pkt ( pkt_bytes ) for header in pkt . keys ( ) : for field in pkt [ header ] . keys ( ) : key = header + '_' + field ind = FEATURES . index ( key ) design_mat [ count , ind ] = pkt [ header ] [ field ] count += 1 return design_mat , time_arr
Parse a pcap file into a numpy matrix.
Parse a pcap file into a numpy matrix .
"""Parse a pcap file into a numpy matrix.
    Inputs:
      - filename : a pcap file that contains packets to parse

    Returns:
      - a numpy matrix where each row is a packet and each column is a
        different field
      - a numpy column array containing the corresponding time of each packet
    """
a numpy matrix where each row is a packet and each column is a
different field
a numpy column array containing the corresponding time of each packet
a numpy matrix where each row is a packet and each column is a different field a numpy column array containing the corresponding time of each packet
filename