Print Friendly, PDF & Email

Difficulty level: Beginner

Approx reading time:

Components Required:

1. Raspberry Pi 3 model B

2. MicroSD card 8 or 16 GB (Class 4 and above) with Raspbian

3. Windows PC / Linux PC (Tested on Windows 10, Ubuntu 14.04 LTS)

4. Ethernet cable (Category 5 – also called Cat 5)

5. Micro USB cable

Way to go ->

1. Login to your Pi using PuTTy or your Ubuntu terminal.

2. Login to your Pi GUI using VNC server (Linux / Windows).

3. In your Pi create a new folder on the Desktop called ipemail by right mouse clicking on the desktop.


4. Open the folder: ipemail, and create new .txt file. Make sure name it as last_ip.txt.


5. Close the folder ipemail.

6. From the menu on the top left open Python 3 (IDLE).


7. In IDLE, create a new file by clicking on File -> New File in the menu bar.


8. Save the file by clicking on File -> Save As… in the menu bar. The file should be saved in folder: ipemail. The name could be:


9. In the file, write the following code with comments (line starting with “#”) for clear understanding and save the file (press Cntrl + S on your PC keyboard).


10. Before running the code, create a new email ID at, eg:-

11. Login to your newly created gmail account.

12. Open, while being logged in to your newly created email account.

13. Google search: Allowing less secure apps to access your gmail account.

14. Follow the instructions by clicking on the first link that google search throws up. (Note:- Following these instructions will enable the python code that you wrote to login to your gmail account and send you your IP address.)


15. After reducing the security of your gmail account. Run the code by clicking on Run -> Run Module in the menu bar. 


16. Check your gmail email account. There you will have received your IP address.


17. You can also check last_ip.txt for your ip address. This file is only updated if your ip address changes.


18. You can run your python script repeatedly or the script can be automated to send an email periodically (eg:- every 2 minutes).

19. To automate the script, type:

in your Pi’s terminal. Type the following at the end of the file to send an email every 2 minutes, if the IP address changes (this what the if-else condition in the python script does.):


20. Press Cntrl + X then Y and finally Enter to save the file.

21. To check whether this works, go to last_ip.txt, make some changes in the IP address and save the file.

22. After 2 minutes, check your newly created gmail email account for your current IP address.

23. You can also check last_ip.txt for your ip address. This file is only updated if your ip address changes.

Read full tutorial at

Rating widget: