cyruz
Occasional Visitor
Hello guys,
this is a simple script I'm using to automatically populate the Client List in the AiMesh section. This is helpful when using an ASUS device as AP, to avoid manual input and managing names on DHCP side...
Cheers!
this is a simple script I'm using to automatically populate the Client List in the AiMesh section. This is helpful when using an ASUS device as AP, to avoid manual input and managing names on DHCP side...
Code:
#!/bin/sh
# arp-clientlist
# --------------
# Poll for new clients in the arp table and modify the nvram custom_clientlist variable.
# The format of each entry is <${hostname}>${mac}>0>42>>, where 42 is the ASUS icon.
# This script should be ran through "cru", adding the following line to "services-start":
# [ -x /jffs/scripts/arp-clientlist ] && cru a arp-clientlist "*/10 * * * * /jffs/scripts/arp-clientlist > /dev/null"
# --------------
# Variables
# ---------
DB_FILE="arp-clientlist-db.txt"
TMP_FILE="/tmp/arp-clientlist-string.tmp"
# ---------
# Ensure DB exists.
[ -f "$DB_FILE" ] || touch "$DB_FILE"
# Parse current arp -a.
arp -a | while read -r hostname rest; do
mac=$(printf "%s\n" "$rest" | awk '{for (i=1;i<=NF;i++) if ($i ~ /:/) {print $i; exit}}')
if [ -n "$mac" ]; then
# Convert MAC to uppercase.
mac=$(printf "%s" "$mac" | tr 'abcdef' 'ABCDEF')
entry="<${hostname}>${mac}>0>42>>"
# Check if entry already exists.
if ! grep -Fxq "$entry" "$DB_FILE"; then
echo "$entry" >> "$DB_FILE"
fi
fi
done
# Build the final string by concatenating everything.
nvram set custom_clientlist=`tr -d '\n' < "$DB_FILE"`
rm -f "$TMP_FILE"
Cheers!