How to Email Yourself Your IP Address

Absinthe, Programming, Website Development

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.
  • sometimes returns nothing for IP. This makes the routine think your IP has changed (into nothing). To avoid this, I put the call to 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.

My script:


SUBJ=”some subject”


touch ip.txt
read ip1 < ip.txt

while [ “$ip2” = “” ]
ip2=$(wget -qO-

if [ “$ip1” = “$ip2” ]
echo “$ip2” > ip.txt
echo “$ip2” | mail -s $SUBJ $EMAIL


2 thoughts on “How to Email Yourself Your IP Address

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s