Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # IP Checker Script
- # Possible sources: https://ipinfo.io, http://ipecho.net/plain, http://ifconfig.me
- if [ ! -f /tmp/ip.txt ]
- then
- echo "" > /tmp/ip.txt
- echo "" > /tmp/last.txt
- fi
- oldip=$(cat /tmp/ip.txt)
- iodata=$(curl -s 'https://ipinfo.io')
- ioip=$(echo ${iodata} | jq -r '.ip')
- if [ "$ioip" != "$oldip" ] || [ "$1" = "run" ]
- then
- iohost=$(echo ${iodata} | jq -r '.hostname')
- iocity=$(echo ${iodata} | jq -r '.city')
- iostate=$(echo ${iodata} | jq -r '.region')
- iocountry=$(echo ${iodata} | jq -r '.country')
- ioloc=$(echo ${iodata} | jq -r '.loc')
- iozip=$(echo ${iodata} | jq -r '.postal')
- ioprovider=$(echo ${iodata} | jq -r '.org')
- thishost=$(hostname)
- namehost=$(echo $thishost | awk '{print toupper($0)}')
- username="USERNAMEHERE"
- password="PASSWORDHERE"
- hostname="HOSTNAMEHERE"
- url="https://${username}:${password}@domains.google.com/nic/update?hostname=${hostname}&myip=${ioip}"
- result=`curl -s $url`
- echo "Subject:PI NOTIFICATION\n\nIP address for $namehost updated\n\nNew IP: $ioip \nOld IP: $oldip \n\nDNS Update Status: $result \n\nISP Details:\n $iohost \n $ioprovider \n $iocity, $iostate $iozip - $iocountry \n GPS:$ioloc " | /usr/sbin/ssmtp EMAIL@EMAIL.com
- echo "$ioip" > /tmp/ip.txt
- echo "$oldip" > /tmp/last.txt
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement