Hello everyone I am running DD-WRT v.3.0 on my Linksys EA6500 router and I have the following script running in order to give me access to the WiFi MAC address that are currently connected to the router:
echo "#!/bin/ash" > /tmp/getmac.sh
echo 'echo { > /tmp/www/list.html' >>/tmp/getmac.sh
echo "for i in \$(arp | awk '{print toupper(\$4)}'); do echo \$i, >> /tmp/www/list.html; done" >>/tmp/getmac.sh
echo 'echo } >> /tmp/www/list.html' >>/tmp/getmac.sh
chmod +x /tmp/getmac.sh
/tmp/getmac.sh
I can visit http://192.168.1.1/user/list.html and it will show me a list of wifi MAC address that are currently connected to the router:
Example:
{ 01:81:18:3d:49:5e, 04:10:87:8c:47:9a, }
However, I would like to modify that to also include the IP ADDRESS and also the NAME OF THE DEVICE.
I found this on the DD-WRT website but when running the command and checking the directory, I do not see it anywhere.
# mkdir -p /tmp/www
while [ 1 ];
do
wl assoclist | awk '{print tolower($2)}' > /tmp/assocLIST
# echo "<meta http-equiv="refresh" content="10"><b>Hostnames and IP addresses of WLAN clients</b> (last update: $(date))<p>" > /tmp/www/wlan.html
while read assocLINE
do
dumpleases | awk '/'"$assocLINE"'/ {print "Hostname: " $1, "MAC: " $2, "IP: " $3}'
# echo "<br>";
done < /tmp/assocLIST # >> /tmp/www/wlan.html
sleep 10;
done;
I would like it to output like so:
{
"data": [{
"IP": "192.168.1.55",
"MAC": "01:81:18:3d:49:5e",
"HOST": "DavidsAndroidPhone"
}, {
"IP": "192.168.1.79",
"MAC": "04:10:87:8c:47:9a",
"HOST": "BobsIphone"
}]
}
Could anyone help me out in modifying my first script I posted to include the IP and NAME?
UPDATE
When I do the command arp in PuTTYtel I get the following info:
DD-WRT login: root
Password:
==========================================================
___ ___ _ _____ ______ ____ ___
/ _ \/ _ \___| | /| / / _ \/_ __/ _ __|_ / / _ \
/ // / // /___/ |/ |/ / , _/ / / | |/ //_ <_/ // /
/____/____/ |__/|__/_/|_| /_/ |___/____(_)___/
DD-WRT v3.0
http://www.dd-wrt.com
==========================================================
BusyBox v1.24.1 (2016-03-07 05:09:22 CET) built-in shell (ash)
root@DD-WRT:~# arp
android-17af243062d3eb6b (192.168.1.144) at 00:ae:fa:4a:3a:4c [ether] on br0
So currently the script I am running (getmac.sh) looks at this and gets only this:
{ 00:ae:fa:4a:3a:4c, }
So given that, how can I modify the script to get more of the information I am looking for in the proper JSON layout?
UPDATE 2
Ok I have this code here:
arp | awk 'BEGIN { print "{" } { print "MAC:" $4 ", IP:" $2 ", HOST:" $1} END { print "}" }'
Which outputs the following:
{
MAC:00:ae:fa:4a:3a:4c, IP:(192.168.1.144), HOST:android-17af243062d3eb6b
}
Now given that above, how can I remove the ( and the ) from the IP and format it in proper JSON form? I've tried awk -F'(' but that doesn't seem to work.