This is a simple hack to findout IP of your home server, if your IP isn't static and changes over time. So you can run this script on your server and retrive the IP whenever you want.
Install requirements using pipenv
pipenv install
Run the script within the virtual environment
pipenv shell
python exposer.py
Use -h
switch to see more options
mosquitto_sub -h test.mosquitto.org -t 'ipexposer/HOSTNAME'
Note: HOSTNAME
is your hostname of your server
After run the script, it tries to connect to a MQTT broker. by default
Mosquitto
free broker has been used, but you
can use any other MQTT broker. After connect to a broker, the script try
to retrive external ip of the server (the IP that is assigned
to your router). For this purpose, the script fetches
this
URL to findout the IP. After that, the IP is published to a topic like
ipexposer/HOSTNAME
, which hostname is hostname of your server.
To lookup the ip, you can simply use a MQTT client like mosquitto_sub
.
Just subscribe to the topic and then you can see the IP. Please note that
if you're using mosquitto.org test broker, it may be a little slow because of its
heavy load. The interesting point is because the script set retain
flag of
published message, you can see the latest IP even if the script is sopped
at the moment.