加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

从pcap文件中提取csv格式的信息(.pcap转换为.csv)

(2014-02-07 07:27:50)
标签:

pcap

csv

转换

文件

it

分类: 代码分析
.pcap文件是二进制格式的网络轨迹(Network trace)文件,记录了网络通信过程的数据包信息。csv(comma separated values)是一种用逗号','分隔的文本文件,类似于excel文件。

.pcap文件是二进制文件,需要从中提取信息并以csv的格式进行存储。可以使用tshark实现对.pcap文件进行分析。

例如,从.pcap文件中提取数据包的mac地址、ip地址、TCP/UDP等可以用以下命令。
tshark -r test.pcap -T fields -e eth.src -e eth.dst -e ip.src -e ip.dst -e ip.proto -E header=y -E separator=, -E quote=d -E occurrence=f > test.csv

-r 指定要分析的.pcap文件
-T fields 说明要对.pcap文件重的fields进行提取
-e filed_name 制定要提取的fields的名字,按照-e的先后顺序,不同的field按列顺序的排列在.csv文件中。
各种field名称可以从wireshark的网站上查询,主要有TCP协议的fileds,IP协议的fields,UDP协议的fields,HTTP协议
-E 指定输出field的格式,包括如下格式:
  • header=y|n If y, print a list of the field names given using -e as the first line of the output; the field name will be separated using the same character as the field values. Defaults to n.
  • separator=/t|/s| Set the separator character to use for fields. If /t tab will be used (this is the default), if /s, a single space will be used. Otherwise any character that can be accepted by the command line as part of the option may be used.
  • occurrence=f|l|a Select which occurrence to use for fields that have multiple occurrences. If f the first occurrence will be used, if l the last occurrence will be used and if a all occurrences will be used (this is the default).
  • aggregator=,|/s| Set the aggregator character to use for fields that have multiple occurrences. If , a comma will be used (this is the default), if /s, a single space will be used. Otherwise any character that can be accepted by the command line as part of the option may be used.
  • quote=d|s|n Set the quote character to use to surround fields. d uses double-quotes, s single-quotes, n no quotes (the default).

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有