Monitor Connected Devices to an ASUS Router Using Raspberry Pi
Tags: tutorial, raspberrypi, router
Published: 2020-04-07 11:19:10

---
title: Monitor Connected Devices to an ASUS Router Using Raspberry Pi
published: true
date: 2020-03-21 08:59:47 UTC
tags: tutorial, RaspberryPi, Router
canonical_url: https://blog.1a23.com/2020/03/21/monitor-connected-devices-to-an-asus-router-using-raspberry-pi/?utm_source=rss&utm_medium=rss&utm_campaign=monitor-connected-devices-to-an-asus-router-using-raspberry-pi
cover_image: https://blog.1a23.com/wp-content/uploads/sites/2/2020/03/Alt-Copy-3.png
---

Title should have explained it all. A simple Python script to monitor if a certain device has connected to the router via Wi-Fi, and send notifications accordingly. You can use this script for whatever purpose you want, though probably you might not be able to find one like most of others.

To use this script, you need SSH access to the router, something in your LAN that is always running (in my case, a Raspberry Pi), and the list of MAC addresses to monitor. In this example, I am using an _ASUS RT-AC1200GU_ as the router. Other brand or make might need a different command.

First of all, SSH access of the router is needed to be enabled. In the router admin panel, go to Advanced Settings → Administration → Service → Enable SSH, select Yes. Put your Raspberry Pi SSH public key into the Authorized Keys box. Then click Apply at the bottom.

![](https://blog.1a23.com/wp-content/uploads/sites/2/2020/03/image-7-1024x394.png)<figcaption>Screenshot of the router admin panel</figcaption>

The key point of this script is to get a list of connected clients via the ARP table of the router. Through testing, the method has been working pretty well, and almost no delay in reflecting the connectivity of devices.

```
ssh admin@192.168.1.1 /sbin/arp -n
? (192.168.1.2) at 00:11:22:33:44:55 [ether] on br0
? (192.168.1.3) at 66:77:88:99:aa:bb [ether] on br0
? (192.168.1.5) at cc:dd:ee:ff:00:11 [ether] on br0
? (192.168.1.7) at 22:33:44:55:66:77 [ether] on br0
? (192.168.1.9) at 88:99:aa:bb:cc:dd [ether] on br0
```

Here you can see a list of devices with their IP and MAC address. We are using MAC address in the script so as to avoid change of IP in case of collision. MAC addresses of your target devices are easy to get from the status page of the router’s admin panel.

This script, written in Python, is ran every 10 minutes through Cron job on my Raspberry Pi. It only notifies when my own device is in the LAN and all devices to monitor are not. It will also reject to run when it cannot see the MAC address of itself is not seen in the list. (This would happen in cases like when the router is down.)

In the script I have used IFTTT Webhook for the notification. That’s because it is something easily enough to trigger in a script, but rarely used by me so that I can whitelist it from my Do Not Disturb mode. You can simply replace line 38 with anything service you want to use.

{% gist https://gist.github.com/blueset/2a648c1a0d96a4118972f425c273afaf %}

![](https://blog.1a23.com/wp-content/uploads/sites/2/2020/03/image-8-909x1024.png)<figcaption>IFTTT activity config.</figcaption>

If you want to directly use this script, there are something that you need to add or change:

- All the MAC addresses at the beginning;
- IP address of your router;
- The credentials of IFTTT Maker Webhook (if you want to use IFTTT);
- Ensure that the status path is writable by the script;
- Install `requests`;
- Setup a cron job to run the script.

As simple as that.

Depending on your router brand and make, ARP table might not be updated as quickly as needed, in which case you may need to find another way to get the device list.

The post [Monitor Connected Devices to an ASUS Router Using Raspberry Pi](https://blog.1a23.com/2020/03/21/monitor-connected-devices-to-an-asus-router-using-raspberry-pi/) appeared first on [1A23 Blog](https://blog.1a23.com).