Skip to content

Instantly share code, notes, and snippets.

@pikesley
Created October 22, 2016 15:55
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pikesley/254e46f686ae48e2c5a509cc3815d31f to your computer and use it in GitHub Desktop.
Save pikesley/254e46f686ae48e2c5a509cc3815d31f to your computer and use it in GitHub Desktop.
Pivertise your Pi

How to Pivertise your Pi

You know how sometimes you connect your Raspberry Pi to a wifi network and then you have absolutely no way of finding out its IP address (Zeroes are particularly bad for this)? Well, I fixed it. Paste the run-once-at-boot-time systemd script into /etc/systemd/system/pivertiser.service and enable it with sudo systemctl enable pivertiser.service, paste the terrible bash hack into /home/pi/pivertiser.sh and chmod +x /home/pi/pivertiser.sh, then reboot your pi and it should show its face over here

Those addresses are stored in a hash keyed on hostname, so clearly if you never rename your pi from raspberrypi then this is an astonishingly terrible solution, but it's just solved a little problem for me. And you can of course run your own instance on Heroku if you want to

#!/bin/bash
sudo /sbin/ifconfig | grep wlan0
if [ ${?} == 0 ] ; then
INTERFACE=wlan0
else
INTERFACE=eth0
fi
curl https://pivertiser.herokuapp.com/`hostname`/`sudo /sbin/ifconfig ${INTERFACE} | grep 'inet addr' | tr -s ' ' ' ' | cut -d ' ' -f 3 | cut -d ':' -f 2`
[Unit]
Description = Advertise our IP
After = network-online.target
[Service]
Type = oneshot
ExecStart = /home/pi/pivertise.sh
[Install]
WantedBy = multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment