Njalla: Difference between revisions

From MikroTik Wiki
Jump to navigation Jump to search
Created page with "Script to update the Njalla Dynamic DNS from RouterOS. <code> # ___ ___ # ________ ___ ______ / / / / _____ # \ \ \__\_\___ \/..."
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
Script to update the Njalla Dynamic DNS from RouterOS.  
Script to update the Njalla Dynamic DNS from RouterOS.  


<code>
  #                            ___  ___
 
  #    ________  ___  ______  /  / /  / _____
#                            ___  ___
  #    \      \ \__\_\___  \/  / /  /_\___  \
#    ________  ___  ______  /  / /  / _____
  #    /  \  / /  /  _  /  /_/  //  _  /
#    \      \ \__\_\___  \/  / /  /_\___  \
  #  /  //  /\/  /    /  /    /  /    /  /
#    /  \  / /  /  _  /  /_/  //  _  /
  #  / __//__/    /\_______\____\___\_______\
#  /  //  /\/  /    /  /    /  /    /  /
  #  \/    \____/
#  / __//__/    /\_______\____\___\_______\
  #
#  \/    \____/
  # Njal.la Dynamic DNS v1.0
#
  #
# Njal.la Dynamic DNS v1.0
  # This script requires these policies: read, policy, test.
#
  #
# This script requires these policies: read, policy, test.
  # To add this to the scheduler, first add this script as "njalla", then use: /system scheduler add interval=5m name=njalla on-event=njalla policy=read,write,policy,test start-time=startup
#
  #
# To add this to the scheduler, first add this script as "njalla", then use: /system scheduler add interval=5m name=njalla on-event=njalla policy=read,write,policy,test start-time=startup
  # Configurable items here:
#
 
# Configurable items here:
  :local domain "<your-domain>"
 
  :local key "<your-key>"
:local domain "<your-domain>"
  :local WANinterface "<your-wan-interface>"
:local key "<your-key>"
 
:local WANinterface "<your-wan-interface>"
  # Leave the rest of the script as is.
 
  :global NjallaIP
# Leave the rest of the script as is.
  :local ipv4addr
:global NjallaIP
 
:local ipv4addr
  :set ipv4addr [/ip address get [/ip address find interface="$WANinterface"] address]
 
  :set ipv4addr [:pick [:tostr $ipv4addr] 0 [:find [:tostr $ipv4addr] "/"]]
:set ipv4addr [/ip address get [/ip address find interface="$WANinterface"] address]
 
:set ipv4addr [:pick [:tostr $ipv4addr] 0 [:find [:tostr $ipv4addr] "/"]]
  :if ([:len $ipv4addr] = 0) do={
 
    :log error ("Could not get IP for interface " . $WANinterface)
:if ([:len $ipv4addr] = 0) do={
    :error ("Could not get IP for interface " . $WANinterface)
  :log error ("Could not get IP for interface " . $WANinterface)
  }
  :error ("Could not get IP for interface " . $WANinterface)
 
}
  :if ($ipv4addr != $NjallaIP) do={
 
      :put "IPv4 address changed to $ipv4addr";
:if ($ipv4addr != $NjallaIP) do={
      :set NjallaIP $ipv4addr;
    :put "IPv4 address changed to $ipv4addr";
      :log info ("Updating dynamic IPv4 address to IP " . $ipv4addr)
    :set NjallaIP $ipv4addr;
      /tool fetch check-certificate=no keep-result=no mode=https url="https://njal.la/update/?h=$domain&k=$key&a=$ipv4addr&quiet"
    :log info ("Updating dynamic IPv4 address to IP " . $ipv4addr)
  } else {
    /tool fetch check-certificate=no keep-result=no mode=https url="https://njal.la/update/?h=$domain&k=$key&a=$ipv4addr&quiet"
      :log info ("Dynamic IPv4 address is still " . $ipv4addr)
} else {
  }
    :log info ("Dynamic IPv4 address is still " . $ipv4addr)
}
</code>

Latest revision as of 14:59, 27 December 2017

Script to update the Njalla Dynamic DNS from RouterOS.

 #                            ___  ___
 #    ________  ___  ______  /  / /  / _____
 #    \       \ \__\_\___  \/  / /  /_\___  \
 #    /   \   / /  /   _   /  /_/  //   _   /
 #   /   //  /\/  /    /  /    /   /    /  /
 #  / __//__/    /\_______\____\___\_______\
 #  \/     \____/
 #
 # Njal.la Dynamic DNS v1.0
 #
 # This script requires these policies: read, policy, test.
 #
 # To add this to the scheduler, first add this script as "njalla", then use: /system scheduler add interval=5m name=njalla on-event=njalla policy=read,write,policy,test start-time=startup
 #
 # Configurable items here:
 
 :local domain "<your-domain>"
 :local key "<your-key>"
 :local WANinterface "<your-wan-interface>"
 
 # Leave the rest of the script as is.
 :global NjallaIP
 :local ipv4addr
 
 :set ipv4addr [/ip address get [/ip address find interface="$WANinterface"] address]
 :set ipv4addr [:pick [:tostr $ipv4addr] 0 [:find [:tostr $ipv4addr] "/"]]
 
 :if ([:len $ipv4addr] = 0) do={
    :log error ("Could not get IP for interface " . $WANinterface)
    :error ("Could not get IP for interface " . $WANinterface)
 }
 
 :if ($ipv4addr != $NjallaIP) do={
     :put "IPv4 address changed to $ipv4addr";
     :set NjallaIP $ipv4addr;
     :log info ("Updating dynamic IPv4 address to IP " . $ipv4addr)
     /tool fetch check-certificate=no keep-result=no mode=https url="https://njal.la/update/?h=$domain&k=$key&a=$ipv4addr&quiet"
 } else {
     :log info ("Dynamic IPv4 address is still " . $ipv4addr)
 }