我正在尝试读取 .pcap 文件,并汇总每个客户端的数据包数(此处的客户端 ip 是目标地址)。例如,如果 5 个数据包已发送到 xxx.ccc.vvv.bbb,我将输出到以下格式的文件中:
xxx.ccc.vvv.bbb 5
这是我在下面编写的程序:
#!/usr/bin/lua
do
numberofpkts = 0
stat = {client1 = {numberofpkts = {}}}
local file = io.open("luawrite","w")
local function init_listener()
local tap = Listener.new("wlan")
local dest_addr = Field.new("wlan.da")
local pkt_type = Field.new("wlan.fc.type")
function tap.reset()
numberofpkts = 0;
end
function tap.packet(pinfo, tvb)
client = dest_addr()
client1 = tostring(client)
type = pkt_type()
if(tostring(type) == '2') then
stat.client1.numberofpkts = stat.client1.numberofpkts+1
file:write(tostring(client1),"\t", tostring(stat.client1.numberofpkts),"\n")
end
end
end
init_listener()
end
在这里,wlan.da 给出了目标地址。wlan.fc.type 表示它是数据包(type = 2)。我在无线流量上使用 tshark 运行它。
我收到一个错误:
tshark: Lua: on packet 3 Error During execution of Listener Packet Callback:
/root/statistics.lua:21: attempt to call field 'tostring' (a nil value)
tshark: Lua: on packet 12 Error During execution of Listener Packet Callback happened 2 times:
/root/statistics.lua:21: attempt to call field 'tostring' (a nil value)
请帮助我应该如何解决这个问题。提前致谢!