查看从 pcap 数据传输了多少数据

Find how much data has been transferred from pcap data

我有一个 pcap 文件,其中包含二进制格式的实验流量跟踪。我想做的是找出不同主机相互交换的数据量,但我对使用 pcap 还很陌生,我一直在搜索和尝试不同的东西但没有成功。

tcpdump 在这里有用吗?我用它处理了原始文件并得到了这样的东西:

2009-12-17 17:26:04.398500 IP 41.177.117.184.1618 > 41.177.3.224.51332: Flags [P.], seq 354231048:354231386, ack 3814681859, win 65535, length 338
2009-12-17 17:26:04.398601 IP 90.218.72.95.10749 > 244.3.160.239.80: Flags [P.], seq 1479609190:1479610159, ack 3766710729, win 17520, length 969
2009-12-17 17:26:04.398810 IP 244.3.160.239.80 > 90.218.72.95.10749: Flags [.], ack 969, win 24820, length 0
2009-12-17 17:26:04.398879 IP 41.177.3.224.51332 > 41.177.117.184.1618: Flags [P.], seq 1:611, ack 338, win 65535, length 610

每行末尾的 "length" 值是否可以很好地指示两台主机相互传输了多少数据?

问题是,如果我用 Wireshark 查看原始文件,似乎这个长度实际上是 TCP header 长度,但是 data/payload 大小在 Wireshark 中单独指定(38 字节对于这四个数据包中的第一个)这让我感到困惑。

所以总结一下 - Wireshark 说(关于第一个数据包):1) “396 字节在线”,2) “96 字节捕获”,3) "len: 338", 4) "Data (38 bytes)".

Tcpdump 说:"length 338"

如何找到负载大小?如果可能,我愿意使用 Python,因为我将处理一个巨大的捕获文件。

tcpdump 在这里有用吗?

是的。

Are the "length" values at the end of each line good indicators of how much data two hosts have transferred to each other?

是的。这是没有 headers.

传输的字节数

How do I find payload size? I'm willing to use Python if possible as I'll > be working with a huge capture file.

您没有指定协议,所以让我们假设 "payload size" 您的意思是 "everything after the IP header"。使用 Python 和 dpkt 很容易做到这一点。根据 Jon's tutorial,假设没有选项的 IP 数据包,一些代码可能会执行您想要的操作,如下所示:

#!/usr/bin/env python

import dpkt
from socket import inet_ntoa

with open("sample.pcap") as f:
    pcap = dpkt.pcap.Reader(f)
    for ts, buf in pcap:
        ip = dpkt.ethernet.Ethernet(buf).data
        print "{} --> {} {}".format(inet_ntoa(ip.src), inet_ntoa(ip.dst), ip.len)