Tutorial 42: Who is Home: Network IP Scanning

This is the first of three tutorials that works on turning your Raspberry Pi into a home greeter bot. The idea is: whenever you return home after work or school your Raspberry Pi sends you a text message welcoming you home. The first step in this project is trying to figure out when you're home without you having to purchase expensive sensing gear or manually interacting with something.

Smart phones are ubiquitous these days, as is Wifi. Everyone has a smart phone on their home wifi network. This can be taken advantage of by having your Pi scan your home's network to see if your cellphone's IP address shows up. In this tutorial I show you how to assign a static IP address to your phone, and how to scan your LAN to see if the phone is on the network.


DIFFICULTY
EASY
LINUX UNDERSTANDING
LITTLE
PYTHON PROGRAMMING
LITTLE
ABOUT
0
MINUTES
  • How to assign a static IP address to a device on your home network
  • How to ping devices on your home network
  • How to interpret the results of the pings
You can copy / paste the code below if you’re having issues with typos or want a shortcut. However I recommend that you follow along in the tutorial to understand what is going on!


import os
from time import sleep

phoneIP = "10.0.1.25" # Change this to match your phone's static IP

while True:
	response = os.system("ping -c 1 " + phoneIP)

	if response == 0:
		print("Phone is online!")
	else:
		print("No phone detected")
	sleep(2)
Everyone has their own router and odds are your router is different from mine. For instructions on how to change a static IP address on your router, check out Port Forward below: