Skip to content

Instantly share code, notes, and snippets.

@vg
Forked from corny/dynv6.sh
Created October 25, 2019 22:36
Show Gist options
  • Save vg/250d6598bd75340c4f57b242d9b9d7c0 to your computer and use it in GitHub Desktop.
Save vg/250d6598bd75340c4f57b242d9b9d7c0 to your computer and use it in GitHub Desktop.

Revisions

  1. @corny corny revised this gist Feb 18, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dynv6.sh
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ fi
    if [ -n "$device" ]; then
    device="dev $device"
    fi
    address=$(ip -6 addr list scope global dynamic $device | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1)
    address=$(ip -6 addr list scope global $device | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1)

    if [ -e /usr/bin/curl ]; then
    bin="curl -fsS"
  2. @corny corny revised this gist Dec 23, 2014. 1 changed file with 11 additions and 8 deletions.
    19 changes: 11 additions & 8 deletions dynv6.sh
    Original file line number Diff line number Diff line change
    @@ -4,19 +4,19 @@ device=$2
    file=$HOME/.dynv6.addr6
    [ -e $file ] && old=`cat $file`

    if [ -z "$hostname" -o -z "$TOKEN" ]; then
    echo "Usage: TOKEN=<your-authentication-token> [netmask=64] $0 your-name.dynv6.net [device]"
    if [ -z "$hostname" -o -z "$token" ]; then
    echo "Usage: token=<your-authentication-token> [netmask=64] $0 your-name.dynv6.net [device]"
    exit 1
    fi

    if [ -n "$netmask" ]; then
    if [ -z "$netmask" ]; then
    netmask=128
    fi

    if [ -n "$device" ]; then
    device="dev $device"
    fi
    current=$(ip -6 addr list scope global dynamic $device | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1)
    address=$(ip -6 addr list scope global dynamic $device | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1)

    if [ -e /usr/bin/curl ]; then
    bin="curl -fsS"
    @@ -27,19 +27,22 @@ else
    exit 1
    fi

    if [ -z "$current" ]; then
    if [ -z "$address" ]; then
    echo "no IPv6 address found"
    exit 1
    fi

    # address with netmask
    current=$address/$netmask

    if [ "$old" = "$current" ]; then
    echo "IPv6 address unchanged"
    exit
    fi

    # send addresses to dynv6
    $bin "http://dynv6.com/api/update?hostname=$hostname&ipv6=$current/$netmask&token=$TOKEN"
    $bin "http://ipv4.dynv6.com/api/update?hostname=$hostname&ipv4=auto&token=$TOKEN"
    $bin "http://dynv6.com/api/update?hostname=$hostname&ipv6=$current&token=$token"
    $bin "http://ipv4.dynv6.com/api/update?hostname=$hostname&ipv4=auto&token=$token"

    # save current address
    echo $current > $file
    echo $current > $file
  3. @corny corny revised this gist Dec 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dynv6.sh
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ fi
    if [ -n "$device" ]; then
    device="dev $device"
    fi
    current=$(ip -6 addr list scope global dynamic $device | grep -v " fd" | egrep -o '([0-9a-f:]+)/[0-9]+' | head -n1)
    current=$(ip -6 addr list scope global dynamic $device | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1)

    if [ -e /usr/bin/curl ]; then
    bin="curl -fsS"
  4. @corny corny revised this gist Dec 21, 2014. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions dynv6.sh
    Original file line number Diff line number Diff line change
    @@ -5,10 +5,14 @@ file=$HOME/.dynv6.addr6
    [ -e $file ] && old=`cat $file`

    if [ -z "$hostname" -o -z "$TOKEN" ]; then
    echo "Usage: TOKEN=<your-authentication-token> $0 your-name.dynv6.net [device]"
    echo "Usage: TOKEN=<your-authentication-token> [netmask=64] $0 your-name.dynv6.net [device]"
    exit 1
    fi

    if [ -n "$netmask" ]; then
    netmask=128
    fi

    if [ -n "$device" ]; then
    device="dev $device"
    fi
    @@ -34,7 +38,7 @@ if [ "$old" = "$current" ]; then
    fi

    # send addresses to dynv6
    $bin "http://dynv6.com/api/update?hostname=$hostname&ipv6=$current&token=$TOKEN"
    $bin "http://dynv6.com/api/update?hostname=$hostname&ipv6=$current/$netmask&token=$TOKEN"
    $bin "http://ipv4.dynv6.com/api/update?hostname=$hostname&ipv4=auto&token=$TOKEN"

    # save current address
  5. @corny corny revised this gist Oct 29, 2014. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions dynv6.sh
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,19 @@
    #!/bin/sh -e
    hostname=$1
    current=$(ip -6 addr list scope global dynamic temporary | grep -v "fd00" | egrep -o '([0-9a-f:]+)/[0-9]+' | head -n1)
    device=$2
    file=$HOME/.dynv6.addr6
    [ -e $file ] && old=`cat $file`

    if [ -z "$hostname" -o -z "$TOKEN" ]; then
    echo "Usage: TOKEN=<your-authentication-token> $0 your-name.dynv6.net"
    echo "Usage: TOKEN=<your-authentication-token> $0 your-name.dynv6.net [device]"
    exit 1
    fi

    if [ -n "$device" ]; then
    device="dev $device"
    fi
    current=$(ip -6 addr list scope global dynamic $device | grep -v " fd" | egrep -o '([0-9a-f:]+)/[0-9]+' | head -n1)

    if [ -e /usr/bin/curl ]; then
    bin="curl -fsS"
    elif [ -e /usr/bin/wget ]; then
  6. @corny corny revised this gist Oct 29, 2014. 1 changed file with 23 additions and 14 deletions.
    37 changes: 23 additions & 14 deletions dynv6.sh
    Original file line number Diff line number Diff line change
    @@ -3,25 +3,34 @@ hostname=$1
    current=$(ip -6 addr list scope global dynamic temporary | grep -v "fd00" | egrep -o '([0-9a-f:]+)/[0-9]+' | head -n1)
    file=$HOME/.dynv6.addr6
    [ -e $file ] && old=`cat $file`

    if [ -z "$hostname" -o -z "$TOKEN" ]; then
    echo "Usage: TOKEN=<your-authentication-token> $0 your-name.dynv6.net"
    exit 1
    echo "Usage: TOKEN=<your-authentication-token> $0 your-name.dynv6.net"
    exit 1
    fi


    if [ -e /usr/bin/curl ]; then
    bin="curl -fsS"
    elif [ -e /usr/bin/wget ]; then
    bin="wget -O-"
    else
    echo "neither curl nor wget found"
    exit 1
    fi

    if [ -z "$current" ]; then
    echo "no IPv6 address found"
    exit 1
    echo "no IPv6 address found"
    exit 1
    fi

    if [ "$old" = "$current" ]; then
    echo "IPv6 address unchanged"
    exit
    echo "IPv6 address unchanged"
    exit
    fi

    # send addresses to dynv6
    curl -fsS "http://dynv6.com/api/update?hostname=$hostname&ipv6=$current&token=$TOKEN"
    curl -fsS "http://ipv4.dynv6.com/api/update?hostname=$hostname&ipv4=auto&token=$TOKEN"
    $bin "http://dynv6.com/api/update?hostname=$hostname&ipv6=$current&token=$TOKEN"
    $bin "http://ipv4.dynv6.com/api/update?hostname=$hostname&ipv4=auto&token=$TOKEN"

    # save current address
    echo $current > $file
    echo $current > $file
  7. @corny corny created this gist Oct 28, 2014.
    27 changes: 27 additions & 0 deletions dynv6.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/bin/sh -e
    hostname=$1
    current=$(ip -6 addr list scope global dynamic temporary | grep -v "fd00" | egrep -o '([0-9a-f:]+)/[0-9]+' | head -n1)
    file=$HOME/.dynv6.addr6
    [ -e $file ] && old=`cat $file`

    if [ -z "$hostname" -o -z "$TOKEN" ]; then
    echo "Usage: TOKEN=<your-authentication-token> $0 your-name.dynv6.net"
    exit 1
    fi

    if [ -z "$current" ]; then
    echo "no IPv6 address found"
    exit 1
    fi

    if [ "$old" = "$current" ]; then
    echo "IPv6 address unchanged"
    exit
    fi

    # send addresses to dynv6
    curl -fsS "http://dynv6.com/api/update?hostname=$hostname&ipv6=$current&token=$TOKEN"
    curl -fsS "http://ipv4.dynv6.com/api/update?hostname=$hostname&ipv4=auto&token=$TOKEN"

    # save current address
    echo $current > $file