Add script to detect public ip address change
This commit is contained in:
parent
8fb1f921bb
commit
c4f7ca2241
2 changed files with 15 additions and 4 deletions
15
scripts/detect-ip-change
Normal file
15
scripts/detect-ip-change
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#!/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
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/bash
|
||||
## Get public IP
|
||||
|
||||
wget http://ipinfo.io/ip -qO -
|
||||
Loading…
Add table
Add a link
Reference in a new issue