Advertisement
cryptomanman

dynv6.sh

Aug 29th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.35 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. #script for ipv6 dynamic dns updating
  4. #based on https://blog.wirelessmoves.com/2016/01/how-to-get-that-dynamic-ipv6-address-to-the-dns-server.html
  5. #and on https://dynv6.com/docs/apis
  6.  
  7. hostname=$HOSTNAME.dynv6.net
  8. device=$2
  9.  
  10. #put your dynv6.com API token here
  11. token=***********************
  12.  
  13. file=/opt/dynv6/.dynv6.addr6
  14. [ -e $file ] && old=`cat $file`
  15.  
  16. if [ -z "$hostname" -o -z "$token" ]; then
  17.   echo "Usage: token=<your-authentication-token> [netmask=64] $0 your-name.dynv6.net [device]"
  18.   exit 1
  19. fi
  20.  
  21. if [ -z "$netmask" ]; then
  22.   netmask=128
  23. fi
  24.  
  25. if [ -n "$device" ]; then
  26.   device="dev $device"
  27. fi
  28. address=$(ip -6 addr list scope global mngtmpaddr $device | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1)
  29.  
  30. if [ -e /usr/bin/curl ]; then
  31.   bin="curl -fsS"
  32. elif [ -e /usr/bin/wget ]; then
  33.   bin="wget -O-"
  34. else
  35.   echo "neither curl nor wget found"
  36.   exit 1
  37. fi
  38.  
  39. if [ -z "$address" ]; then
  40.   echo "no IPv6 address found"
  41.   exit 1
  42. fi
  43.  
  44. # address with netmask
  45. current=$address/$netmask
  46.  
  47. if [ "$old" = "$current" ]; then
  48.   echo "IPv6 address unchanged"
  49.   exit
  50. fi
  51.  
  52. # send addresses to dynv6
  53. $bin "http://dynv6.com/api/update?hostname=$hostname&ipv6=$current&token=$token"
  54. echo "http://dynv6.com/api/update?hostname=$hostname&ipv6=$current&token=$token"
  55.  
  56. # save current address
  57. echo $current > $file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement