Skip to content

Where is my PI?

  • by

raspberry-pi-580-75[1]Hashtag[1]Unless you use static IP’s or a DHCP reserved IP for your PI (or really, any Linux based computer) how do you know where it lives on your network?  This might not be an immediate issue for you on your home network, but what if you take your PI with you to another network for some reason?  It could also be used to simply let you know when a machine has been rebooted and is back on line..

Read on to find out how I fixed this problem…

Welcome back,

Ok, so I wanted to know what the IP of my PI (did you notice that PI is a Palindrome for IP?).  Why would it be an issue, you might be asking yourself?   Here is a scenario, your PI does something cool and you just have to take it over to your friends house and show off.  You don’t need a keyboard and mouse plugged in because your too cool for peripherals, you only need an HDMI cable, power and Ethernet (or even WIFI perhaps), so you wire up your PI and see it boot on the TV and it’s up. Awesome but how do you SSH or browse to your PI?

Enter the script, send-myip. (<—Download the script by clicking there)

There is no configuration required to use this script, only 2 command line arguments are needed to make it work, however if you plan use the SMS function you will require a script to handle this for you. When I’m using the script for SMS I have it call another script I created send-sms (click on that to read my previous posting on this script)..  You can edit the script to hard code an email address (or addresses) in the TO= variable near the top of the script.

One of the things this script does is collect IP’s for all active interfaces on the machine (excluding the loopback interface), so if you have ETH0 and WLAN0 your messages will contain both IP’s.  If you’re using this on a machine with a load of virtual interfaces then you may want to edit the script to only collect from ETH0 or whatever single interface you want to know about.

Running the script with no options will dump the help page

You must provide at least 1 argument on the command line.

The first argument MUST be one of these actions:

sms     – This will send an sms AND email to rob
email   – This will ONLY send an email, used mostly for debugging
all     – Send both Email and SMS
help    – Display this page

Other optional formats for the above arguments can be:

–sms   | sms   | SMS
–email | email | EMAIL
–all   | all   | ALL
–help  | help  | HELP | (nothing at all)

The second argument is optional but can be an email address to send to if
you are using the EMAIL or ALL option above.

ie:     ./send-myip –sms
./send-myip EMAIL
./send-myip –help


That really is it in the nut bash shell.   The script is pretty simple and does the job well enough for my needs, hopefully someone else can find a use for the script too.