我想使用python代码将pcap文件转换为csv;但问题是我应该准确指定要使用 tshark 库导出的字段。我想导出所有字段。当我不指定字段时,将导出空白文件。示例代码如下:
tshark -r /root to the file/test1.pcap -T fields -e ip.src > test1.csv
我想删除特殊字段以导出所有字段;然后访问 python 中的字段(使用像 pandas 这样的库,采用字典格式,如 df["Source"])
感谢任何帮助!
最佳答案
I want to remove the special fields to export ALL fields;
这对于 CSV(字段)格式来说是不可能的
$tshark -r trace.pcap -T fields
tshark: "-Tfields" was specified, but no fields were specified with "-e".
另一种解决方案是使用 JSON 格式 (-T ek|json|jsonraw
) 或 XML 格式 (-T pdml
) 之一。
then accessing the fields in python (using a library like pandas in dictionary format like df["Source"])
在 python 中,您可以使用 json.lodas() 解析 JSON 并获取字典。请参阅https://www.w3schools.com/python/python_json.asp
关于python - 在python中将pcap文件中的所有字段导出到csv中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58821744/