How to Find Out Which Devices Are Connected to Your Network

by scanos in Circuits > Raspberry Pi

326 Views, 0 Favorites, 0 Comments

How to Find Out Which Devices Are Connected to Your Network

web.png

It's prudent to know which devices are connected to your LAN and what their uptime is. Maybe, you want advanced warning if a key server is down if your solar powered IOT devices has enough juice to transmit temperature,say. I wrote this simple bash script to do exactly that.

What you need

A Linux device such as a Raspberry Pi

Admin access to the Linux device

An editor such as Nano to create files and scripts

Apache or other web server

Introduction to the Script

web.png

This uses nmap scans to search for ip addresses and then update hostname,ip and time on a local file (PART 1)

The records from the local file, including last seen, are written on the fly to a web page (PART 2). This creates a historical record of every device and ip address that has been on the network. To run the script you need CLI admin access on your Linux device, in my case a Raspberry Pi. I use the script as follows, adding the subnet as an argument,e.g. ./check_alive_nmap.sh 192.168.8.0/24

How to Install and Run the Script

1. Open your Pi and install git if you don't have it already. I am using the home directory of the user logged on , e.g. /home/pi/ or ~/

2. sudo git install https://github.com/scanos/connectmyplace.git

3. sudo cp connectmyplace/nmap_monitor_esp/check_alive_nmap.sh ~/ (home directory)

4. sudo chmod 755 ~/check_alive_nmap.sh

5. sudo chmod 755 ~/check_alive_nmap.sh

6. Create a web page - touch /var/www/html/live_ipaddress.html ( you need Apache installed and default /var/www/html/ root directory.

7. sudo chmod 777 /var/www/html/live_ipaddress.htm

8. You are now ready to run the script - ./check_alive_nmap.sh 192.168.8.0/24 (change the argument to that of your sub net )

9. You can cron the script, a typical crontab entry is */15 * * * * cd /home/pi/;./check_alive_nmap.sh 192.168.8.0/24 (This runs the script every 15 minutes)

10. Remove the git - sudo rm -r ~/connectmyplace

Update

click_through.png

I added a feature whereby you can click on the IP address of the device and access its web page if it had one. This is particular useful if you have a Pi running a web server or a wifi enabled IOT device - see the example above of one of my Tasmota based IOT devices (Witty Cloud).