Add script to detect public ip address changes

This commit is contained in:
sonny 2018-05-09 23:16:14 +02:00
parent 8fb1f921bb
commit d91d0a661f
2 changed files with 16 additions and 4 deletions

16
scripts/detect-ip-change Executable file
View file

@ -0,0 +1,16 @@
#!/bin/bash
# Send an email when the public ipv4 address changes
if [[ -a /tmp/ipv4_address ]]; then
CURRENT_IP=$(/usr/bin/dig +short myip.opendns.com @resolver1.opendns.com)
PREVIOUS_IP=$(cat /tmp/ipv4_address)
if [[ $CURRENT_IP != $PREVIOUS_IP ]]; then
echo "IP address changed from $PREVIOUS_IP to $CURRENT_IP" | /usr/bin/mail -s 'IP address changed' sonnyba871@gmail.com
echo $CURRENT_IP > /tmp/ipv4_address
echo "Mail sent"
fi
else
echo "$(/home/sonny/dotfiles/scripts/pubip)" > /tmp/ipv4_address
fi

View file

@ -1,4 +0,0 @@
#!/bin/bash
## Get public IP
wget http://ipinfo.io/ip -qO -