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