1 -- module to access linux ARP cache
3 config = require "config"
6 _ARPCACHE4 = '/sbin/ip -4 n'
7 _PING6 = '/bin/ping6 -c 1 -W 1'
8 _ARPCACHE6 = '/sbin/ip -6 n'
10 function _match_v4(ip)
11 return string.match(ip,"%d*%.%d*%.%d*%.%d*")
16 function _arpcache.get_mac(ip)
18 local rec = _arpcache.cache[ip]
19 if rec and rec.timestamp+config.arp_ttl > os.time() then
27 os.execute(_PING6..' '..ip)
31 local f = io.popen(cmd)
44 for k in string.gmatch(line, "(%S+)") do
57 _arpcache.cache[ip] = { mac = res, timestamp = os.time() }