<%# Copyright 2008 Steven Barth Copyright 2008-2011 Jo-Philipp Wich Licensed to the public under the Apache License 2.0. -%> <% local util = require "luci.util" local function online_data() local rv = { } local fd = util.execi('/usr/bin/awk \'BEGIN{while ((getline < "/tmp/dhcp.leases") > 0){a[$2]=$4;}while ((getline < "/proc/net/arp") > 0){if (!a[$4]){a[$4]="\?";}if (match($3,"0x[26]")){"ping -q -c 1 "$1" &";if (b[$4]){b[$4]=b[$4]"/"$1;}else{b[$4]=$1;}c[$4]=$6;}}while (("ip -6 neighbor show | grep -v fe80" | getline) > 0){if (b[$5]) {"ping -q -c 1 "$1" &";b[$5]=b[$5]"/"$1;}}for (mac in b){print(a[mac],b[mac],mac,c[mac]);}}\' ') while true do local ln = fd() if ln == nil then break end local name,ip,mac,dev = ln:match("^(%S+) (%S+) (%S+) (%S+)") if mac and ip and name and dev then rv[#rv+1] = { hostname = name, device = dev, macaddr = mac, ipaddr = ip } end end return rv end if luci.http.formvalue("status") == "1" then local rv = { onlines = online_data() } luci.http.prepare_content("application/json") luci.http.write_json(rv) return end -%> <%+header%>

<%:Status%>

<%:Online User%>
<%:Hostname%> <%:IPv4-Address%> <%:MAC-Address%> <%:Interface%>

<%:Collecting data...%>
<%+footer%>