dnsping_v6.sh 670 B

123456789101112131415161718192021222324252627
  1. #! /bin/bash
  2. # This script will determine the current IPv6 address of the host and call
  3. # an external URL to update the dynamic dns entry
  4. user=""
  5. password=""
  6. server_url=""
  7. if [ -e /tmp/dnsping_oldaddr ];
  8. then
  9. old_addr=$(cat /tmp/dnsping_oldaddr)
  10. else
  11. old_addr=""
  12. fi
  13. new_addr=$(ip -o -6 addr | grep -v -e fc00:: -e fd00:: | grep global | grep -v "preferred_lft 0sec" | grep -v temporary | awk '{print $4}' | cut -d "/" -f 1)
  14. if [ "$old_addr" != "$new_addr" ];
  15. then
  16. if [ ! -z "$new_addr" ];
  17. then
  18. echo "detected new ip address: $new_addr"
  19. curl --user ${user}:${password} "https://${server_url}/?ipv6=$new_addr"
  20. echo "$new_addr" > /tmp/dnsping_oldaddr
  21. fi
  22. fi