Appendix A

Function for Parsing Packets from pcap Files

The following function is for parsing packets from pcap files for Chapter 13:

def parse_scapy_packets(packetlist):     count=0     datalist=[]     for packet in packetlist:         dpack={}         dpack['id']=str(count)         dpack['len']=str(len(packet))         dpack['timestamp']=datetime.datetime.fromtimestamp(packet.time)\                                   .strftime('%Y-%m-%d %H:%M:%S.%f')         if packet.haslayer(Ether):             dpack.setdefault('esrc',packet[Ether].src)             dpack.setdefault('edst',packet[Ether].dst)             dpack.setdefault('etype',str(packet[Ether].type))         if packet.haslayer(Dot1Q):             dpack.setdefault('vlan',str(packet[Dot1Q].vlan)) ...

Get Data Analytics for IT Networks: Developing Innovative Use Cases, First Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.