Advertisement
Guest User

ipcheck

a guest
Jan 28th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.27 KB | None | 0 0
  1. #!/bin/sh
  2. # IP Checker Script
  3. # Possible sources: https://ipinfo.io, http://ipecho.net/plain, http://ifconfig.me
  4.  
  5. if [ ! -f /tmp/ip.txt ]
  6. then
  7.     echo "" > /tmp/ip.txt
  8.     echo "" > /tmp/last.txt
  9. fi
  10.  
  11. oldip=$(cat /tmp/ip.txt)
  12. iodata=$(curl -s 'https://ipinfo.io')
  13. ioip=$(echo ${iodata} | jq -r '.ip')
  14.  
  15. if [ "$ioip" != "$oldip" ] || [ "$1" = "run" ]
  16. then
  17.     iohost=$(echo ${iodata} | jq -r '.hostname')
  18.     iocity=$(echo ${iodata} | jq -r '.city')
  19.     iostate=$(echo ${iodata} | jq -r '.region')
  20.     iocountry=$(echo ${iodata} | jq -r '.country')
  21.     ioloc=$(echo ${iodata} | jq -r '.loc')
  22.     iozip=$(echo ${iodata} | jq -r '.postal')
  23.     ioprovider=$(echo ${iodata} | jq -r '.org')
  24.     thishost=$(hostname)
  25.     namehost=$(echo $thishost | awk '{print toupper($0)}')
  26.  
  27.     username="USERNAMEHERE"
  28.     password="PASSWORDHERE"
  29.     hostname="HOSTNAMEHERE"
  30.     url="https://${username}:${password}@domains.google.com/nic/update?hostname=${hostname}&myip=${ioip}"
  31.     result=`curl -s $url`
  32.     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
  33.     echo "$ioip" > /tmp/ip.txt
  34.     echo "$oldip" > /tmp/last.txt
  35. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement