wireshark按端口计数数据包

时间:2012-11-27 20:31:09

标签: tcp wireshark packets

我有一个非常大的跟踪文件,我正在尝试使用Wireshark来确定哪个目标端口发送的数据包最多。有没有办法获取发送到特定端口的数据包的计数?或者按发送端口的数据包数排序?

1 个答案:

答案 0 :(得分:0)

你可以在lua中写一个简单的wireshark listener

local tap 

local ports = {} 

local function packet(pinfo, tvb, userdata)
    -- store number of packets per each port
    local port = pinfo.dst_port
    ports[port] = (ports[port] or 0) + 1
end

local function draw(userdata)

    local maxi,maxv = 0,0
    -- print all gathered statictics and find max
    for i,v in pairs(ports) do
        print(i .. ":",  v)
        if maxv < v then
            maxi,maxv = i,v
        end
    end
    print ("Max:", maxi, maxv)
end

local function reset(userdata)
    ports = {}
end

local function show_ports()
    tap = Listener.new()
    tap.packet = packet
    tap.draw = draw 
    tap.reset = reset 
end

register_stat_cmd_arg('ports', show_ports)

试一试:

tshark -X lua_script:ports.lua -z ports -r in.pcap