如何按端口获取数据包统计信息



是否有更好的方法来获取端口统计信息,例如源端口的STAT或目标端口?

例如,获得如下:

的结果
  --------------------------------
  | Src/Dst Port | Packets Count |
  | -----------------------------|
  |   22         | 100           |
  | -----------------------------|
  |   80         | 200           |
  |------------------------------|
  |   8080       | 300           |
  | -----------------------------|

我已经检查了Wireshark的统计菜单和TSHARK命令,但仍然不知道如何获得我想要的结果。

我不相信可以直接从Wireshark或tshark获得此摘要信息,但是您可能可以编写一个脚本来完成。

这是一个可以帮助您入门的脚本:

#!/bin/sh
# Check usage
if (( ${#} < 2 )) ; then
        echo "Usage: $0 <file> <type> ... where type is udp or tcp"
        exit 1
fi
# Sanity check if the file specified actually exists or not
stat ${1} &> /dev/null
if [ $? -ne 0 ] ; then
        echo "File ${1} doesn't exist"
        exit 2
fi
# Validate the type
if [ "${2}" != "udp" -a "${2}" != "tcp" ] ; then
        echo "Invalid type ${2}.  Specify either udp or tcp."
        exit 3
fi
echo "Src/Dst Port | Packets Count"
tshark -nq -r ${1} -z endpoints,${2} | grep "^[1-9]" | tr -s ' ' | cut -s -d ' ' -f 2,3 | sort -n | gawk '{arr[$1]+=$2} END {for (i in arr) {print i,arr[i]}}'

最新更新