What's new

Command to get active devices on the network

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

sma

New Around Here
Hi there - is there a command I can run on the router while connected over SSH that provides a list of active devices on the network in the same way that the "Client Status" screen shows on the home page? I'd like to integrate this into a monitoring script to determine when network devices connect or disconnect from the network. The script will be run every 30 seconds or so. I've tried finding the relevant page in the source code to try figure this out myself but I couldn't work it out.
Thanks!
 
Hi there - is there a command I can run on the router while connected over SSH that provides a list of active devices on the network in the same way that the "Client Status" screen shows on the home page? I'd like to integrate this into a monitoring script to determine when network devices connect or disconnect from the network. The script will be run every 30 seconds or so. I've tried finding the relevant page in the source code to try figure this out myself but I couldn't work it out.
Thanks!
The ip neigh command will show the ip and mac address of the device.

arp -a will show description if available, IP address and MAC address.
 
The ip neigh command will show the ip and mac address of the device.

arp -a will show description if available, IP address and MAC address.
Hey - thanks, that looks perfect.

Cheers.

EventPhotoMan - I'll report back when I make progress.
 
Hey - thanks, that looks perfect.

Cheers.

EventPhotoMan - I'll report back when I make progress.
I can use this too!

I placed this in /jffs/configs/profile.add.

Code:
Clients () {
    GREEN='\033[0;32m'
    NC='\033[0m' # No Color

    printf '%b%-23s %-15s %-17s%b\n' "$GREEN" "Description         " "IP Address    " "MAC Address      "  "$NC"
    arp -a | sed 's/(//;s/)//' | while read -r DESC IP AT MAC ETH ON IFACE
    do
        printf '%-23s %-15s %-17s\n' "$DESC" "$IP" "$MAC"
    done
}

Start a new SSH session to activate. Type Clients at the SSH command line to run.

You may need to adjust the length of the description field. I may look at it again tomorrow so I don't have to pipe to a temp file.

EDIT=>CODE UPDATED to remove piping output to temp file!
 
Last edited:
You may need to adjust the length of the description field. I may look at it again tomorrow so I don't have to pipe to a temp file.

Very useful @Xentrk, thanks for sharing :) One question: which value do I need to adjust to increase the length of the description field? I don't have lot of knowledge of shell scripting, so a pointer in the right direction would be greatly appreciated :rolleyes:
 
Last edited by a moderator:
Pinging @ColinTaylor who has a similar script in use already
Thanks for the heads up Jack.

@sma I have a script that I use that monitors when wireless devices connect and disconnect. The trouble is that it doesn't work with the Quantenna routers, and it can't detect wired devices. But you're more than welcome to have a look at it.

The only way I know to monitor all devices, wired and wireless, is with the ip neigh command that @Xentrk suggested. I don't know how accurate that would be at detecting when a device has disconnected as opposed to just being idle.... Hmmm... I feel a new script coming on.:D
 
Very useful @Xentrk, thanks for sharing :) One question: which value do I need to adjust to increase the length of the description field? I don't have lot of knowledge of shell scripting, so a pointer in the right direction would be greatly appreciated :rolleyes:
The -23 is the length of the Description field and data values. You would need to adjust the two lines of printf code to change the length.
 
I recently wrote similar functions that may be useful to others. I'll post them on github later today and provide a link when done.
 
I started a repo on github for miscellaneous scripts and included the Clients function.

I posted two scripts so far. One is profile.add and x3mtek_Chk_ADNS.sh. You can see the README.md for descriptions at https://github.com/Xentrk/Asuswrt-Merlin-Linux-Shell-Scripts. I'll update the repo with some more scripts soon.

Here is how to download profile.add
Code:
curl "https://raw.githubusercontent.com/Xentrk/Asuswrt-Merlin-Linux-Shell-Scripts/master/profile.add" -o /jffs/configs/profile.add[code]
Will download x3mtek_Chk_ADNS.sh and execute it
Code:
curl "https://raw.githubusercontent.com/Xentrk/Asuswrt-Merlin-Linux-Shell-Scripts/master/x3mtek_Chk_ADNS.sh" -o /jffs/scripts/x3mtek_Chk_ADNS.sh && chmod +x /jffs/scripts/x3mtek_Chk_ADNS.sh && sh /jffs/scripts/x3mtek_Chk_ADNS.sh[code]
 
I started a repo on github for miscellaneous scripts and included the Clients function.

Awesome @Xentrk, looking forward to other useful scripts and additions. Thanks again for sharing!

One remark regarding the Clients function in profile.add: it does appear to show clients which already have disconnected, correct? My wife left for work but it still showed her iPhone with its IP when running Clients, allthough the MAC address showed up as 'incomplete'.

J75LduT.png


Is there a way to filter whether a client is actually still connected or has recently disconnected? (assuming the 'incomplete' MAC address is caused by her recently leaving?
 
I can use this too!

I placed this in /jffs/configs/profile.add.

Code:
Clients () {
    GREEN='\033[0;32m'
    NC='\033[0m' # No Color

    printf '%b%-23s %-15s %-17s%b\n' "$GREEN" "Description         " "IP Address    " "MAC Address      "  "$NC"
    arp -a | sed 's/(//;s/)//' | while read -r DESC IP AT MAC ETH ON IFACE
    do
        printf '%-23s %-15s %-17s\n' "$DESC" "$IP" "$MAC"
    done
}

Start a new SSH session to activate. Type Clients at the SSH command line to run.

You may need to adjust the length of the description field. I may look at it again tomorrow so I don't have to pipe to a temp file.

EDIT=>CODE UPDATED to remove piping output to temp file!


Hi Xentrk thank you for scripts - how do you get /jffs/configs entries like your profile.add to be read without booting the router - will wan-start do it?
 
Hi Xentrk thank you for scripts - how do you get /jffs/configs entries like your profile.add to be read without booting the router - will wan-start do it?
For profile.add just log out of your SSH session and back in again.
 
Thanks
 
I can use this too!

I placed this in /jffs/configs/profile.add.

Code:
Clients () {
    GREEN='\033[0;32m'
    NC='\033[0m' # No Color

    printf '%b%-23s %-15s %-17s%b\n' "$GREEN" "Description         " "IP Address    " "MAC Address      "  "$NC"
    arp -a | sed 's/(//;s/)//' | while read -r DESC IP AT MAC ETH ON IFACE
    do
        printf '%-23s %-15s %-17s\n' "$DESC" "$IP" "$MAC"
    done
}

FYI not quite as concise as yours :D; ARPDevices.sh, but sometimes it is useful to force an ARP refresh, and also to extract a custom description if the device is legitimately (temporarily) offline/dormant.
 
FYI not quite as concise as yours :D; ARPDevices.sh, but sometimes it is useful to force an ARP refresh, and also to extract a custom description if the device is legitimately (temporarily) offline/dormant.
:D Sweet! I'm impressed. Once again, I bow down to your Jedi Master coding skills. Thank you for sharing!
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top