loading
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:

http://youtu.be/4B592qe2LWQ

Step 1: Download Raspberry Pi Code for This Project

Download the code for this project here:

https://justpaste.it/iphonescan

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 2025551212@txt.att.net 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 justpaste.it into the blank window in IDLE and save the file (name it something like iphonescan.py)

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.
<p>Nice Idea</p><p>I implemented this myself...</p><p>Although I used arping -c 2 xxx.xxx.xxx.xxx &gt;&gt; /dev/null</p>
<p>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?</p>
<p>Hey, thanks. There could be a few different reasons for this. Check the following:</p><p>1. Goes without saying, but double check that you typed in your iPhone's Wi-Fi MAC address correctly into the python script</p><p>2. Is your iPhone's ip address 192.168.<strong>2</strong>.(something)? If not and it's something like 192.168.<strong>1</strong>.(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:</p><p>For instance, if your iPhone's IP is 192.168.1.4, you'll need to change the nmap line in the code to this:</p><blockquote>response = os.popen(&quot;sudo nmap -sP 192.168.<strong>1</strong>.1/24 | grep &quot; + IphoneMac + &quot; | awk '{print$3}' &quot;,&quot;r&quot;).readline()</blockquote><p>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.</p><p>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.</p><p>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. </p>
<p>Yea I downloaded nmap and tried testing stuff on that directly. I realized the ip address range should be in 192.168.1.xxx instead of 192.168.2.xxx. Thanks a lot it works now.</p>
<p>Is it possible to add multiple mac address?</p><p>and thanks for sharing :)</p>
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).
<p>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.</p><p>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:</p><p>IphoneMac = &quot;23:34:12:23:54:53&quot;</p><p>IphoneMac2 = &quot;13:34:12:23:54:53&quot;</p><p>IphoneMac3 = &quot;53:34:12:23:54:53&quot; </p><p>2. Add an nmap call for each of the MAC addresses you're searching for. The code should look something like this:</p><p>response = os.popen(&quot;sudo nmap -sP 192.168.2.1/24 | grep &quot; + IphoneMac + &quot; | awk '{print$3}' &quot;,&quot;r&quot;).readline()</p><p>response2 = os.popen(&quot;sudo nmap -sP 192.168.2.1/24 | grep &quot; + IphoneMac2 + &quot; | awk '{print$3}' &quot;,&quot;r&quot;).readline()</p><p>response3 = os.popen(&quot;sudo nmap -sP 192.168.2.1/24 | grep &quot; + IphoneMac3 + &quot; | awk '{print$3}' &quot;,&quot;r&quot;).readline()</p><p>3. Strip the newline character from each of the additional responses. Code should look like this:</p><p>response = response.rstrip('\n')</p><p>response2 = response2.rstrip('\n')</p><p>response3 = response3.rstrip('\n')</p><p>4. Edit the If statement to check for all 3 MACs instead of just the one. The updated If statement should like this:</p><p>if ((response == IphoneMac) or (response2 == IphoneMac2) or (response3 == IphoneMac3)):</p><p>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. </p>
<p>Thanks for sharing this!</p>

About This Instructable

2,195views

43favorites

License:

More by jfetchitown17:Send Email+TXT when you return home (detects when iPhone rejoins network) 
Add instructable to: