I’ve used the instructions here to set up a script that emails my desktop’s IP address to me.
Their instructions are five years old, so I had to make some additions:
- In Gmail, you need to enable Access to Less Secure Apps.
- I had to add ‘touch ip.txt’ to their bash script right before ‘read ip1 < ip.txt’, otherwise the script just hung at that line forever.
- ifconfig.me sometimes returns nothing for IP. This makes the routine think your IP has changed (into nothing). To avoid this, I put the call to ifconfig.me inside a while loop that tries to call again until it gets a response.
I need to email myself my IP because, otherwise, my ISP might change my IP address (a la dynamic IP), and then I wouldn’t know where to find my website anymore.
Since now I will always be able to find my home IP, I can always access my website from anywhere in the world.
read ip1 < ip.txt
while [ “$ip2” = “” ]
ip2=$(wget -qO- ifconfig.me/ip)
if [ “$ip1” = “$ip2” ]
echo “$ip2” > ip.txt
echo “$ip2” | mail -s $SUBJ $EMAIL