projects
/
lua-squid-acl-helper.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Добыча MAC для IPv6 (с предварительным "прощупыванием" хоста для его попадания в...
[lua-squid-acl-helper.git]
/
src
/
arpcache.lua
diff --git
a/src/arpcache.lua
b/src/arpcache.lua
index 1ae8136f09bb18d1bfa96ddaea99a6ae3e20baaa..329439aee6f9153058fb93d21408c428ebbf1161 100644
(file)
--- a/
src/arpcache.lua
+++ b/
src/arpcache.lua
@@
-4,18
+4,27
@@
config = require "config"
_arpcache = {}
_ARPCACHE4 = '/sbin/ip -4 n'
_arpcache = {}
_ARPCACHE4 = '/sbin/ip -4 n'
+_PING6 = '/bin/ping6 -c 1 -W 1'
_ARPCACHE6 = '/sbin/ip -6 n'
function _match_v4(ip)
return string.match(ip,"%d*%.%d*%.%d*%.%d*")
end
_ARPCACHE6 = '/sbin/ip -6 n'
function _match_v4(ip)
return string.match(ip,"%d*%.%d*%.%d*%.%d*")
end
+_arpcache.cache = {}
+
function _arpcache.get_mac(ip)
function _arpcache.get_mac(ip)
+ local rec = _arpcache.cache[ip]
+ if rec and rec.timestamp+config.arp_ttl > os.time() then
+ return rec["mac"]
+ end
+
local cmd
if _match_v4(ip) then
cmd = _ARPCACHE4
else
local cmd
if _match_v4(ip) then
cmd = _ARPCACHE4
else
+ os.execute(_PING6..' '..ip)
cmd = _ARPCACHE6
end
cmd = _ARPCACHE6
end
@@
-38,11
+47,16
@@
function _arpcache.get_mac(ip)
if w[1]==ip then
res = w[5]
if w[1]==ip then
res = w[5]
+
break
end
end
break
end
end
+ if res then
+ _arpcache.cache[ip] = { mac = res, timestamp = os.time() }
+ end
+
f:close()
return res
f:close()
return res