Netscan

I frequently use my Wi-Fi for connecting to the internet. One annoying quirk that I found with my setup was that there is no easy way to determine which devices have connected to my wifi. Some routers, come with these kind of monitoring tools, but mine did not. So, I wanted to make a script that does just that.

I realised that if I ping my network broadcast address, then I will get the IP of all the devices that are connected to the network. Since, most systems, use a simple Class-C network, we can detremine this IP quite easily. If my laptop is connected to the wifi, and have a local IP of say, 192.168.56.98 then I know that the broadcast IP will be 192.168.56.255, since that is the general convention. So, if I ping this IP I will receive packets from all the devices that are connected to my wifi.

Then, I also need to map the name of indivisual devices with there IP address allocated to them. For this, I wrote a setup script. It prompts the user with questions about the broadcast network of there wifi, and number of devices they need to monitor. Then it also, prompts the user with information about the IP address of each device and the name associated with them. This script writes these results in a formatted manner to the error stream that is pipelined (using a bash script) to a .env file. This file contains the environment variables for the main script, that pings the network.

Now, every time when you want to scan the network, you simple call my main.py script, and it will read all the variables from the environment file and scan the network for potentially connected devices.

There is a very obvious glaring issue with the project, at this stage. If DHCP is enabled on the router (which is very comman), then the assigned private IP of all the devices change frequently. So, ideally to use the software, setup script should be run quite often to correctly map all the devices with there allocated IP addresses. Also, this method of asking user about the IP of devices, is something that I want to avoid altogether. Some script to do this will reduce the onboarding friction a lot. I am planning to add that functionality in the future.

The code is open-sourced here.