updatedns.sh 844 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/sh
  2. echo "Current time: $(date "+%Y-%m-%d %H:%M:%S")"
  3. ip_file="ip"
  4. new_ip=$(curl -s http://ipecho.net/plain)
  5. # Fallbacks
  6. if [ -z "$new_ip" ]; then
  7. new_ip=$(curl -s http://whatismyip.akamai.com)
  8. fi
  9. if [ -z "$new_ip" ]; then
  10. new_ip=$(curl -s http://icanhazip.com/)
  11. fi
  12. if [ -z "$new_ip" ]; then
  13. new_ip=$(curl -s https://tnx.nl/ip)
  14. fi
  15. if [ -z "$new_ip" ]; then
  16. echo "Empty IP !"
  17. exit 0
  18. fi
  19. if [ -f $ip_file ]; then
  20. ip=$(cat $ip_file)
  21. if [ "$ip" = "$new_ip" ]; then
  22. echo "Same ip: $ip"
  23. exit 0
  24. fi
  25. fi
  26. update=$(curl -s -X GET "https://ip4.ddnss.de/upd.php?key=c1eed0f30eaa1a599570f18def222738&host=metzner.myhome-server.de")
  27. if echo "$update" | grep -q "Updated 1 hostname"; then
  28. echo "DDNSS-IP changed to: $new_ip"
  29. echo "$new_ip" > $ip_file
  30. else
  31. printf "Update failed:\\n%s" "$update"
  32. exit 1
  33. fi