code: def packet2dict(packet):
      
      dict_ = dict()
      frame = packet.frame_info
      for field in frame.field_names:
          dict_[field] = getattr(frame, field)
  
      tempdict = dict_
      for layer in packet.layers:
          tempdict[layer.layer_name.upper()] = dict()
          tempdict = tempdict[layer.layer_name.upper()]
          for field in layer.field_names:
              tempdict[field] = getattr(layer, field)
  
      return dict_
docs: Convert PyShark packet into dict.