如何使用.pcapng文件计算Wire-Shark上的平均数据包到达时间?
我在WIRE-SHARK上捕获了一些数据包,因此我必须对其进行分析。 当然,我已经尝试对“鲨鱼”上的“分析”选项卡做一些事情,但是我找不到找到平均数据包到达时间的有效方法。
有什么有效的方法可以找到它吗?
答案 0 :(得分:0)
我刚刚为此编写了一个pdml2flow
插件:pdml2flow-frame-inter-arrival-time。
当前它尚未发布到pip
,因此您需要自己git clone && python setup.py install
插件。但是一旦完成,您就可以:
dump.capture
中打印到达时间:$ tshark -r dump.capture -Tpdml | pdml2flow +frame-inter-arrival-time
{"inter_arrival_times": [7.152557373046875e-07, 0.0, 0.1733696460723877], "frames": null}
{"inter_arrival_times": [3.7670135498046875e-05, 2.3126602172851562e-05], "frames": null}
{"inter_arrival_times": [0.16418147087097168, 0.0007672309875488281, 0.16009950637817383, 0.00016069412231445312, 0.0007240772247314453, 0.15914177894592285, 3.814697265625e-05, 5.245208740234375e-06], "frames": null}
{"inter_arrival_times": [0.1608715057373047, 0.15995335578918457, 2.384185791015625e-07, 2.384185791015625e-07, 2.384185791015625e-07, 0.15888381004333496], "frames": null}
{"inter_arrival_times": [0.16829872131347656, 0.0007762908935546875, 0.14913678169250488, 0.000125885009765625, 0.000736236572265625, 10.19379997253418], "frames": null}
$ tshark -r dump.capture -Tpdml | pdml2flow -f frame.interface_name +frame-inter-arrival-time
{"inter_arrival_times": [7.152557373046875e-07, 0.0, 0.00018739700317382812, 3.7670135498046875e-05, 2.3126602172851562e-05, 0.008971691131591797, 0.16414976119995117, 4.76837158203125e-07, 3.123283386230469e-05, 0.0007672309875488281, 0.16007304191589355, 2.6464462280273438e-05, 0.00016069412231445312, 0.0007240772247314453, 0.1590421199798584, 2.384185791015625e-07, 2.384185791015625e-07, 2.384185791015625e-07, 9.894371032714844e-05, 3.814697265625e-05, 5.245208740234375e-06, 0.0006232261657714844, 0.15811824798583984, 0.010167837142944336, 1.2636184692382812e-05, 0.0007762908935546875, 0.14911913871765137, 1.7642974853515625e-05, 0.000125885009765625, 0.000736236572265625, 0.16014313697814941, 0.035120248794555664, 0.2039034366607666, 1.907348632, ... ] }
$ tshark -r dump.capture -Tpdml | pdml2flow +frame-inter-arrival-time --no_flow
0.0
7.152557373046875e-07
0.0
0.00018739700317382812
3.7670135498046875e-05
2.3126602172851562e-05
0.008971691131591797
0.16414976119995117
4.76837158203125e-07
3.123283386230469e-05
插件逻辑在以下位置实现:
plugin/plugin.py
[a305598]:计算帧的到达时间
# vim: set fenc=utf8 ts=4 sw=4 et :
from pdml2flow.plugin import Plugin2
from argparse import ArgumentParser
from json import dumps
argparser = ArgumentParser('Calculate inter arrival times of frames in a flow or on an interface')
DEFAULT_NO_FLOW = False
argparser.add_argument(
'--no_flow',
action = 'store_true',
dest = 'no_flow',
default = DEFAULT_NO_FLOW,
help = 'Calculate inter arrival time to the previous frame on the interface, not in the flow [default: {}]'.format(
DEFAULT_NO_FLOW
)
)
PRINT_FRAMES = False
argparser.add_argument(
'--frames',
action = 'store_true',
dest = 'frames',
default = PRINT_FRAMES,
help = 'Print the frames alongside the inter arrival time [default: {}]'.format(
PRINT_FRAMES,
)
)
def _get_frame_time(x):
return x['frame']['time_epoch']['raw']
class Plugin(Plugin2):
@staticmethod
def help():
"""Return a help string."""
return argparser.format_help()
def __init__(self, *args):
"""Called once during startup."""
self._args = argparser.parse_args(args)
self._last_frame_time = None
def flow_end(self, flow):
"""Calculate and print the frame inter-arrival time."""
if not self._args.no_flow:
inter_arrival_times = []
prev_t = None
for t in _get_frame_time(flow.frames):
if prev_t:
inter_arrival_times.append(
t - prev_t
)
prev_t = t
print(
dumps({
'inter_arrival_times': inter_arrival_times,
'frames': flow.frames if self._args.frames else None
})
)
def frame_new(self, frame, flow):
"""Calculate and print the frame inter-arrival time."""
if self._args.no_flow:
frame_time_now = _get_frame_time(frame)[0]
if not self._last_frame_time:
self._last_frame_time = frame_time_now
print(
frame_time_now - self._last_frame_time
)
self._last_frame_time = frame_time_now
if __name__ == '__main__':
print(Plugin.help())
我希望这会有所帮助。反馈/功能或更改请求始终受到欢迎。 :)