GalaxyData Community

Mikrotik dynv6 scypt autoupdate hostname for DNS IPv4 and IPv6

Заходим в System / Scripts.  Добавляем новый скрипт. Назовем “dynv6”, название пригодится в планировщике.

https://gist.github.com/stargieg/1b11d3df9cc6f9cb934037e6c474d618

# Define User Variables
:global ddnspass "TOKEN"
:global ddnshost "HOSTNAME.dynv6.net"
#:global ddnspool "pool0"
#:global ddnsinterface "bridge"
#:global ddnsinterface "6to4-henet"
#:global ddnsinterface "pppoe-out1"
#:global ddnsinterface "ether1"

# Define Global Variables
:global ddnsip
:global ddnslastip
:if ([ :typeof $ddnslastip ] = nil ) do={ :global ddnslastip "0" }


# Define Local Variables
:local int

# Loop thru interfaces and look for ones containing
# default gateways without routing-marks
:if ([ :typeof $ddnsinterface ] != "str" ) do={
  :foreach int in=[ /ipv6 address find global ] do={
    :local testip [ /ipv6 address get $int address ]
    :if ($testip in "fe80::/10" || $testip in "fc00::/7") do={
    } else={
      :global ddnsip $testip
    }
  }
} else={
  :if ([ :typeof $ddnspool ] != "str" ) do={
    # Grab the current Global IP address on that interface.
    :foreach int in=[ /ipv6 address find interface=$ddnsinterface global ] do={
      :local testip [ /ipv6 address get $int address ]
      :if ($testip in "fe80::/10" || $testip in "fc00::/7") do={
      } else={
        :global ddnsip $testip
      }
    }
  } else={
    # Grab the current Global IP address on that interface from spec ip pool.
    :global ddnsip [ /ipv6 address get [ /ipv6 address find interface=$ddnsinterface  from-pool=$ddnspool ] address ]
  }
}

# Did we get an IP address to compare?
:if ([ :typeof $ddnsip ] = nil ) do={
   :log info ("DynDNS: No ip address present on please check.")
} else={
  :log info ("DynDNS: check IPv6 UPDATE " . $ddnsip)
  :if ($ddnsip != $ddnslastip) do={
    :log info "DynDNS: Sending IPv6 UPDATE!"
    :local str "api/update\?hostname=$ddnshost&ipv6=$ddnsip&token=$ddnspass"
    /tool fetch address="dynv6.com" host="dynv6.com" src-path="$str" mode=https dst-path=("/dynv6.".$ddnshost)
    :delay 1
    :local str [/file find name="dynv6.$ddnshost"];
    /file remove $str
    :global ddnslastip $ddnsip
  }
}

# legacy IPv4
# Define Global Variables
:global ddnsip4
:global ddnslastip4
:global ddnsinterface4
:if ([ :typeof $ddnslastip4 ] = nil ) do={ :global ddnslastip4 "0" }

# Loop thru interfaces and look for ones containing
# default gateways without routing-marks
:local intfinder ""
:foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes ] do={
  :set $intfinder [:tostr [/ip route get $int gateway-status]]
  :set $intfinder [:pick $intfinder ([:find $intfinder "via"]+5) [:len $intfinder]]
  :set $ddnsinterface4 $intfinder
}

# Grab the current IP address on that interface.
:set ddnsip4 [ /ip address get [/ip address find interface=$ddnsinterface4 ] address ]
:set ddnsip4 [:pick $ddnsip4 0 [:find $ddnsip4 "/"] ]

# Did we get an IP address to compare?
:if ([ :typeof $ddnsip4 ] = nil ) do={
  :log info ("DynDNS: No ip address present on " . $ddnsinterface4 . ", please check.")
} else={
  :log info ("DynDNS: check IPv4 UPDATE " . $ddnsip4)
  :if ($ddnsip4 != $ddnslastip4) do={
    :log info "DynDNS: Sending IPv4 UPDATE!"
    :local str "api/update\?hostname=$ddnshost&ipv4=$ddnsip4&token=$ddnspass"
    /tool fetch address="dynv6.com" host="dynv6.com" src-path="$str" mode=https dst-path=("/dynv6.".$ddnshost)
    :delay 1
    :local str [/file find name="DynDNS.$ddnshost"];
    /file remove $str
    :global ddnslastip4 $ddnsip4
  }
}

Где за место:

:global ddnspass “TOKEN”
:global ddnshost “HOSTNAME.dynv6.net”

Указываем ваш токен из настроек https://dynv6.com/users/edit:

И ваш созданный hostname: https://dynv6.com/hosts

:global ddnspass “s3VyFvtByyYRf4fZxVpynodArtFxx9”
:global ddnshost “nustromo.dynv6.net”

Пример добавления dynv6:

Заходим в System / Scheduler и добавляем новое задание.

Или в консоли вводим

/system scheduler add name=dynv6 interval=00:30 on-event="/system script run dynv6\r\n"

Не ставьте интервал обновления больше 10 минут!
Иначе dynv6 может заблокировать вас.

Exit mobile version