Home Raspberry Pi Rapsberry Pi - Dynamic IP updater

Rapsberry Pi – Dynamic IP updater

Your IP changes often? Always stay up to date without a DNS!

One of the readers asked me how I found the IP address of my Raspberry Pi from China. I had DNS and my IP is fairly static, but that got me thinking.  You could install automatic updater and use free DNS like  noip.com. What if you want to know your actual external IP when it changes? The Dynamic IP updater – is here to help you.

Dynamic IP updater

This is a Python3 script that runs on a Raspberry Pi, monitors the changes every X minutes and notifies you if the address changes, by sending your an AutoRemote message. If you don’t know what AutoRemote is here is more about how to use it with Raspberry Pi. The message can be displayed on a PC, or mobile and used with Tasker.

While IP can be scraped from a website, I found a neat library on github. Make sure you have pip installed:

sudo apt-get install python3 pip

and then install the library from github:

sudo pip3 install ipgetter

You will need to get the google key from AutoRemote for each device you want to notify about the IP change. Just visit associated AutoRemote URL and you will be able to get it:

https://autoremotejoaomgcd.appspot.com/?key=[it's the part that is here]

Now you are ready to fill in the blanks. This is a Python3 script:

import ipgetter
import urllib.request
import requests

currentIP = ipgetter.myip()
#AutoRemote function to send a notification YOUR_KEY goes here
def sendAR(x):
	AR_key = 'YOUR_KEY'
	AR_url = 'https://autoremotejoaomgcd.appspot.com/sendmessage?key='+ AR_key +'&message=IP%20'
	message = AR_url + x
	response = urllib.request.urlopen(message).read()
#check the internet  and check if previous file is present
	print('Internet present')
	IPfile = open('ipfile.txt', 'r')
	lastIP = IPfile.read()	
	if lastIP == currentIP:
		print('No changes last IP: ' + lastIP + ' current IP: ' + currentIP)
		with open('ipfile.txt', 'w+') as f:
			print('IP updated')
#handle no file			
except IOError:
	with open('ipfile.txt', 'w+') as f:
		IPfile = ipgetter.myip()
		print('created file with current IP')
#Handle no internet		
except requests.ConnectionError:

Short explanation. Initially, the script will create the file and issue an AR notification. If you want to notify more than one device, duplicate the sendAR() function [sendAR1(), sendAR2()], changing the keys and add the newly created functions to the script.

When the script runs, the new IP is compared to the one in the file, and if a difference is found, a notification is issued. Otherwise, nothing happens as there is nothing to report. There is also an exception to terminate the script if no network is present.

Scheduling the dynamic IP updater

Instead of running this script constantly in the background schedule it to run as often as you wish with a crontab.

crontab -e

Create new line ie:

0 7 * * * python3 /path/script.py

if you want to run the script once a day at 7:00 am. You can read more on schedule with crontab here.

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.


Nothing says "Thank you" better than keeping my coffee jar topped up!


Support me on Patreon and get an early access to tutorial files and videos.


Bitcoin (BTC)

Use this QR to keep me caffeinated with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU


Programable, ESP32 based awesome dev platform with 4.7 e-ink display by M5Stack

More HATs

Argon One M.2

Enclose Raspberry Pi 4 inside this great case with custom I/O, cooling and GPIO and M.2 SSD support

More cases on

Best Raspberry Pi Projects

How to use Raspberry PI as WOL (wake on lan) server

While you could wake up your PC from a mobile directly, having a dedicated server capable of doing so is the best solution. The reason is simple. You can hook up as many devices as you wish with a single endpoint. This is why Raspberry Pi is perfect for this.

How fast Raspberry Pi NAS is?

Let's see how fast Raspberry Pi NAS really is?

Argon18: Argon ONE SSD modification

Argon One case just got better - now you can boot it from USB without ruining the design thanks to Argon 18: Argon One SSD modification

The most pointless upgrade to my NAS – Raspberry Pi 3B+

This upgrade is almost pointless!


C/C++ and MicroPython SDK for Raspberry Pi Pico on Windows

A guide to SDK toolchain for Raspberry Pi Pico and C/C++ , Micropython on Windows.

A comprehensive guide to Grafana & InfluxDB

How to use Grafana and InfluxDB on Raspberry Pi for IoT sensors in home automation

How to boot Raspberry Pi 4 from USB

How to set up and boot Raspberry Pi 4 from USB drive - headless guide.

Raspberry Pi Zero, Raspberry Pi 3A+ WiFi without keyboard or cables

Getting Raspberry Pi boards connected in seconds

Everything you need to start using JSON

It's JSON not Jason, just saying!