从pcap文件中提取时间和源IP地址

时间:2013-03-20 22:01:15

标签: awk pcap tcpdump

我有pcap跟踪文件,我想从数据包中提取时间和源IP地址。我正在使用tcpdump和awk。以下是文件的示例

 02:00:00.001814 IP 61.31.228.1.80 > 0.106.173.16.19999: Flags [S.], seq 4049606604, ack        4044405336, win 512, length 0
 02:00:00.005787 IP 61.31.228.1.80 > 0.4.173.19.13923: Flags [S.], seq 3812128115, ack 3811406374, win 512, length 0
 02:00:00.005799 IP 74.54.182.242.80 > 0.176.229.61.43527: Flags [S.], seq 61247722, ack 352633207, win 65535, options [mss 1460,nop,nop,sackOK], length 0

然后我应用awk来提取csv文件中的时间和源IP地址:

02:00:00.001814,0.106.173.16.19999:
02:00:00.005787,0.4.173.19.13923:
02:00:00.005799,0.176.229.61.43527:

我只对最后一点感兴趣,我想摆脱源ip结束时的“:”。我用过

awk '{print $1 "," $5}'

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

试试这个:

 awk -F'[:. ]' '$5=="IP"{print $4","$12"."$13"."$14"."$15}'

输出

001814,0.106.173.16
005787,0.4.173.19
005799,0.176.229.61