| ホスト検索 |
function search_host(mac)
sw_route = nil
route = nil
port = nil
rtn, str = rt.command("show status switching-hub macaddress " .. mac)
port = string.match(str, "port (%d):")
if (port) then
route = "LAN1:" .. port
else
rtn, str = rt.command("show arp lan2")
if (string.match(str, mac)) then
route = "LAN2"
else
rtn, str = rt.command("show arp lan3")
if (string.match(str, mac)) then
route = "LAN3"
end
end
end
if (not route) then
return
end
while true do
rtn, str = rt.command("switch control function get status-macaddress-addr " ..
mac .." " .. route)
if (rtn) and (str ~= "0 entry\r\n") then
port = string.match(str, "(%d+)")
sw_route = route
route = route .."-" ..port
else
break
end
end
return sw_route, port
end
|
| メインルーチン |
local rtn, str
local fhs, estr, ecode
local buf
while (true) do
rtn, str = rt.syslogwatch(ptn)
mac = string.match(str[1], mac_ptn)
if (mac) then
sw_route, port = search_host(mac)
if (sw_route) and (port) then
fh, estr, ecode = io.open(filename, "a")
if (not fh) then
rt.syslog(log_level, "file open error (" .. estr ..")")
else
buf = str[1]
rtn, str = rt.command("switch control function get system-name " ..
sw_route)
name = string.match(str, "(.-)\r\n")
if (name) then
buf = buf .. " at " .. name
else
buf = buf .. " at " .. sw_route
end
buf = buf .. " : port " .. port
buf = buf .. "\r\n"
fh:write(buf)
fh:flush()
fh:close()
end
end
end
end
|