如何通过端口

时间:2017-11-22 02:33:01

标签: wireshark

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

例如获得如下结果:

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

我检查过wireshark的Statistics菜单和tshark命令,但仍然不知道如何获得我想要的结果。

1 个答案:

答案 0 :(得分:1)

我不相信可以直接从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]}}'
相关问题