Send Email+TXT When You Return Home (detects When IPhone Rejoins Network)

This project sends a daily text message and email alert when your iPhone gets close to your Wi-Fi network, such as when you return home. The alerts are limited to send only once a day and only during a user selected time window, such as 4-8 PM. The program is written in Python and introduces basic concepts for beginners learning to use the Raspberry Pi.

Video how-to for this project:

Step 1: Download Raspberry Pi Code for This Project

Download the code for this project here:

Step 2: Download Nmap to Your Raspberry Pi

Open a terminal window on your raspberry pi (click on lxterminal on the raspian desktop) and type this to install nmap:

sudo apt-get install nmap

Step 3: Personalize the Code for Your Email Address and Phone Number

The code clearly indicates where you need to enter the following:

1. The email address that you want alerts sent to (i.e. Where you receive alerts)

2. The email address and password of the account that you want to send alerts from

3. The phone number that you want to alerts sent to. You'll need to input the appropriate email-sms gateway for this phone number, all of which are noted in the code for major cell phone providers. For instance, you would type in to send a text message to phone number 202-555-1212 if that phone number is an AT&T subscriber.

4. The MAC address of the smartphone you carry with you. This is the phone that the program will constantly search for on your home network and will detect when you first return home.

Step 4: Run the Program!

Open IDLE on your Raspian desktop. Paste the code you just copied from into the blank window in IDLE and save the file (name it something like

Click on RUN and then click on RUN MODULE. You should see a new Python shell pop up and the program start to search for your iPhone.



    • Pets Challenge

      Pets Challenge
    • 1 Hour Challenge

      1 Hour Challenge
    • Fandom Contest

      Fandom Contest

    7 Discussions


    4 years ago on Introduction

    Nice Idea

    I implemented this myself...

    Although I used arping -c 2 >> /dev/null

    Hey I really loved this tutorial but for some reason I cannot find my iPhone on the network. Do you know what might have caused this?

    4 replies

    Hey, thanks. There could be a few different reasons for this. Check the following:

    1. Goes without saying, but double check that you typed in your iPhone's Wi-Fi MAC address correctly into the python script

    2. Is your iPhone's ip address 192.168.2.(something)? If not and it's something like 192.168.1.(something) or 10.0.0.(something), then just go and edit the line of code in the python script to reflect your router's subnet:

    For instance, if your iPhone's IP is, you'll need to change the nmap line in the code to this:

    response = os.popen("sudo nmap -sP | grep " + IphoneMac + " | awk '{print$3}' ","r").readline()

    3. As I noted in the video, even if everything is working perfectly, sometimes nmap won't find my iPhone on the network if my iphone is idle and not pulling/pushing data. However, that doesn't matter for this project because when my iPhone rejoins my WiFi network, at that moment nmap is, in fact, able to find it.

    A. The way I did a lot of my testing was to get the python script up and running on the RaspPI while my iPhone is in Airplane mode. You can easily simulate your arrival back to your house by getting out of airplane mode and triggering your iphone to rejoin your WiFi network, just like when you pull the driveway.

    Let me know if that stuff fixes it. If you get really stuck, try messing around with nmap directly on the command line while your iPhone is pulling/pushing data to help me narrow down what the issue is.

    Yea I downloaded nmap and tried testing stuff on that directly. I realized the ip address range should be in instead of Thanks a lot it works now.


    Reply 4 years ago on Introduction

    Actually, now that I think about it, there is a much easier way to do what you want. Just open three different terminal windows on your Raspberry Pi and run the program three times simultaneously (with each program searching for a different MAC address).


    Reply 4 years ago on Introduction

    Good idea and, yeah, this should be pretty easy if you do it quick and dirty and don't care about what is displayed on the screen (just that the program is actually detecting 3 MACs not 1 MAC). Here are some tips and, if there is interest, I can post updated code.

    1. Add additional variables at the top of the program for each additional smartphone you want to detect. The code should look something like this:

    IphoneMac = "23:34:12:23:54:53"

    IphoneMac2 = "13:34:12:23:54:53"

    IphoneMac3 = "53:34:12:23:54:53"

    2. Add an nmap call for each of the MAC addresses you're searching for. The code should look something like this:

    response = os.popen("sudo nmap -sP | grep " + IphoneMac + " | awk '{print$3}' ","r").readline()

    response2 = os.popen("sudo nmap -sP | grep " + IphoneMac2 + " | awk '{print$3}' ","r").readline()

    response3 = os.popen("sudo nmap -sP | grep " + IphoneMac3 + " | awk '{print$3}' ","r").readline()

    3. Strip the newline character from each of the additional responses. Code should look like this:

    response = response.rstrip('\n')

    response2 = response2.rstrip('\n')

    response3 = response3.rstrip('\n')

    4. Edit the If statement to check for all 3 MACs instead of just the one. The updated If statement should like this:

    if ((response == IphoneMac) or (response2 == IphoneMac2) or (response3 == IphoneMac3)):

    5. That should work, but isn't the cleanest way to implement this. The program will still print out that it is only searching for the 1 smartphone without additional changes, however, in the background it'll actually be searching for all 3 smartphones.