Giter VIP home page Giter VIP logo

pi-ip's Introduction

Pi IP

A simple shell script that triggers an IFTTT webhook to POST the device's local IP address.

My use case is a headless SSH device on a network where you cannot make its local IP static, such as a Raspberry Pi on a University Network.

Requirements

The script requires netcat and curl. You'll need git to clone the repo and a text editor like nano to edit the .env file. You'll need cron if you want to set up a cronjob to run on startup.

If you're intending to use a wireless network, you must configure your device to use the wireless network and ensure that your device automatically connects to that network on startup.

Setup

Getting the Files

Ensure git is installed, then clone the git repo.

git clone https://github.com/ethmth/pi-ip.git
cd pi-ip/

Select Network Interface

Determine your device's wireless or wired network interface, whichever you want to determine the local IP of. ip a gives a list of network interfaces on your device. A common wireless interface is wlan0.

Edit the .env file with your network interface.

INTERFACE_NAME=<your_network_interface>

Put your interface in place of <your_network_interface>, For example: INTERFACE_NAME=wlan0

NOTE: The .env file may be hidden, but if you cloned this repo from GitHub and entered its directory, it will be there. You can edit it by typing nano .env.

IFTTT Setup

Register an IFTTT account, then create an applet.

For the If This service, select "Webhooks" then "Receive a web request with a JSON payload". Call the event name something you'll remember, such as pi_awoken.

Add the event name to the .env file.

IFTTT_EVENT=<your_event_name>

For the Then That service, you could theoretically select anything, but I selected "Send an email."

Once the Applet is created, go to ifttt.com/maker_webhooks and click Documentation. It should say "Your key is: <your_key>". Copy the key, then add it to the .env file.

IFTTT_KEY=<your_key>

You can put whatever you'd like for the IFTTT_MESSAGE.

Running the Script

Test the Setup

Make the script executable.

chmod +x ipcheck.sh

Once you added the environment variables to the .env file, test the script by running it.

./ipcheck.sh

If you set it up correctly, your IFTTT event should get triggered with the local IP address info of your device.

Run on Startup/Detect IP Changes

If you would like this script to run on startup, and tell you the local IP address of your device every time it turns on, I would recommend setting up a cronjob.

crontab -e # Edit your crontab

Then, add the following lines, replacing the directory with the directory you cloned the git repo into.

*/5 * * * * /home/$USER/pi-ip/ipcheck.sh
@reboot /home/$USER/pi-ip/ipcheck.sh startup

The first line will cause the script to check for local IP updates every 5 minutes, which is probably not necessary. The second line will cause the script to check for local IP updates every time the system boots up, which you will likely want to enable.

pi-ip's People

Contributors

ethmth avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.