From 3d4e1cbad158cbd24e66b30b61af8733026d2345 Mon Sep 17 00:00:00 2001 From: Ghost <166657596+vr-ski@users.noreply.github.com> Date: Fri, 3 Apr 2026 16:35:01 +0300 Subject: [PATCH] add filter by state --- README.md | 19 +++++++++++++++++-- list-clients | 12 ++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 83e0bb1..2509e13 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,15 @@ echo elap=0 -ip neigh | sort | while read -r l; do +# Parse parameter +if [ $# -ge 1 ]; +then + FILTER=$(awk 'BEGIN{print toupper("'"$1"'")}') +else + FILTER=""; +fi + +ip neigh | sort | grep "${FILTER}" | while read -r l; do ip=$(echo "$l" | awk '{print $1}') ifc=$(echo "$l" | sed -n 's/.* dev \([^ ]*\).*/\1/p') mac=$(echo "$l" | sed -n 's/.* lladdr \([^ ]*\).*/\1/p') @@ -100,9 +108,16 @@ done THE_END ``` - +## Usage Now you can simply run it as `list-clients` and add it as a Custom command (System > Custom commands) to LuCi!
Optionally you can install `iw` or `iwinfo` to if you want your wireless SSID to be resolved as fallback for Iface. +Optional parameter to filter state: you can also run the command, followed by the desired state in any combination of upper or lower case characters. +Example: +```console +list-clients REACHABLE +``` + + Note that command might not work properly if not run with root privileges. Also, the `list-clients` itself does not require `bash` to run so after you are done with the install script, you can uninstall bash if you want... diff --git a/list-clients b/list-clients index 848a90b..0d6e9bf 100644 --- a/list-clients +++ b/list-clients @@ -14,7 +14,15 @@ echo elap=0 -ip neigh | sort | while read -r l; do +# Parse parameter +if [ $# -ge 1 ]; +then + FILTER=$(awk 'BEGIN{print toupper("'"$1"'")}') +else + FILTER=""; +fi + +ip neigh | sort | grep "${FILTER}" | while read -r l; do ip=$(echo "$l" | awk '{print $1}') ifc=$(echo "$l" | sed -n 's/.* dev \([^ ]*\).*/\1/p') mac=$(echo "$l" | sed -n 's/.* lladdr \([^ ]*\).*/\1/p') @@ -65,4 +73,4 @@ ip neigh | sort | while read -r l; do [ -z "$owrtIfc" ] && owrtIfc="-" printf "%-28s %-17s %-34.34s %-25.25s %-22.22s %-10s %-10s\n" "$ip" "$mac" "$vend" "$host" "$owrtIfc ($ifc)" "$meth" "$state" -done \ No newline at end of file +done