no-ip script for failover wan needed?

Hi, I found this epic script somewhere on the net and have 1 problem, and its :global ddnsinterface “ether10”

I’ve got 2 WAN connections set on failover, ether10 @wan1 distance1 and ether9@wan2 distance2, its not the best option, but it kinda works, so my question is, can the script be changed so that ether9 can be used when ether10 is offline or unstable to reach the web 8.8.8.8 or whatever




# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# EDIT YOUR DETAILS / CONFIGURATION HERE
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Define DDNS Accounts for RB Interfaces, one per interface.

# The RB interface
:global ddnsinterface "ether10"
# The DDNS Provider (Choice of NOIP, DYNDNS or EVERYDNS)
:global ddnsprovider "NOIP"
# The Hostname to update.
:global ddnshost ""
# Your Account Username
:global ddnsuser ""
# Your Account Password
:global ddnspass ""


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# END OF USER DEFINED CONFIGURATION
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Define Global Variables
:global ddnssystem ("mt-" . [/system package get system version] )

:global ddnsip
:global ddnslastip
:if ([ :typeof $ddnslastip;] = "nil" ) do={ :set ddnslastip "0" }

:global ddnsprovname
:global str
:global ddnsprovaddress
:if ($ddnsprovider="NOIP") do={
  :set ddnsprovname "NoIP"
  :set str "/nic/update?hostname=$ddnshost&myip=$ddnsip"
  :set ddnsprovaddress "dynupdate.no-ip.com"
} 
if ($ddnsprovider="DYNDNS") do={
  :set ddnsprovname "DynDNS"
  :set str "/nic/update?hostname=$ddnshost&myip=$ddnsip&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
  :set ddnsprovaddress "members.dyndns.org"
}
if ($ddnsprovider="EVERYDNS") do={
  :set ddnsprovname "EveryDNS"
  :set str "/index.php?ver=0.1&ip=$ddnsip&domain=$ddnshost"
  :set ddnsprovaddress "dyn.everydns.net"
}


# Grab the current IP address on that interface.
:global ddnsip2 [/ip address get [/ip address find interface=$ddnsinterface ] address];
:set ddnsip [:pick $ddnsip2 0 [:find $ddnsip2 "/"]];

# Did we get an IP address to compare?
:if ([ :typeof $ddnsip;] = "nil" ) do={
   :log info ("NoIP: No ip address present on " . $ddnsinterface . ", please check.")
} else={
  :if ($ddnsip != $ddnslastip) do={
        :log info "$ddnsprovname: Sending UPDATE!"
         /tool fetch address=$ddnsprovaddress src-path=$str mode=http user=$ddnsuser password=$ddnspass dst-path=("/DDNS-".$ddnsprovname.".".$ddnshost)
  }
  :delay 1
  :set str [/file find name="DDNS-$ddnsprovname.$ddnshost"];
  /file remove $str
  :set ddnslastip $ddnsip
}

#:log info "DDNS Update script executed successfully."

anyone? …did I post in the wrong section?

simple mode on: add 2 script, one for wan1 and other for wan2 (you need 2 ddns account), then you can choose for by which connection you would enter to the router

1 problem, the NAS devices is set on resolving 1 DNS for server

*set up global variable holding active interface name
*set up script that will set that global variable with active interface name, like - main itnerface and backup interface and if main is up, backup should be used
*change your current script to use the global variable with current active interface name.

to use this global variable successfully use script and scheduler as they can share same user space and variables will be created within it. Netwatch uses different user to run its scripts.

I’ve lost you there, but I’ve got a failover setup with 2 WAN’s, and netwatch is going to keep showing online, becuase wan2 will kick in after wan1 died

first add two script

one with:

:if ( [/ping 8.8.8.8 interface=ether10 count=3 ] = 0 ) do={set interface eth9}

other with

:if ( [/ping 8.8.8.8 interface=ether10 count=3 ] = 3 ) do={set interface eth10}

this is the script for update

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# EDIT YOUR DETAILS / CONFIGURATION HERE
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Define DDNS Accounts for RB Interfaces, one per interface.

# The RB interface
:global ddnsinterface $interface
# The DDNS Provider (Choice of NOIP, DYNDNS or EVERYDNS)
:global ddnsprovider "NOIP"
# The Hostname to update.
:global ddnshost ""
# Your Account Username
:global ddnsuser ""
# Your Account Password
:global ddnspass ""


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# END OF USER DEFINED CONFIGURATION
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Define Global Variables
:global ddnssystem ("mt-" . [/system package get system version] )

:global ddnsip
:global ddnslastip
:if ([ :typeof $ddnslastip;] = "nil" ) do={ :set ddnslastip "0" }

:global ddnsprovname
:global str
:global ddnsprovaddress
:if ($ddnsprovider="NOIP") do={
  :set ddnsprovname "NoIP"
  :set str "/nic/update?hostname=$ddnshost&myip=$ddnsip"
  :set ddnsprovaddress "dynupdate.no-ip.com"
}
if ($ddnsprovider="DYNDNS") do={
  :set ddnsprovname "DynDNS"
  :set str "/nic/update?hostname=$ddnshost&myip=$ddnsip&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
  :set ddnsprovaddress "members.dyndns.org"
}
if ($ddnsprovider="EVERYDNS") do={
  :set ddnsprovname "EveryDNS"
  :set str "/index.php?ver=0.1&ip=$ddnsip&domain=$ddnshost"
  :set ddnsprovaddress "dyn.everydns.net"
}


# Grab the current IP address on that interface.
:global ddnsip2 [/ip address get [/ip address find interface=$ddnsinterface ] address];
:set ddnsip [:pick $ddnsip2 0 [:find $ddnsip2 "/"]];

# Did we get an IP address to compare?
:if ([ :typeof $ddnsip;] = "nil" ) do={
   :log info ("NoIP: No ip address present on " . $ddnsinterface . ", please check.")
} else={
  :if ($ddnsip != $ddnslastip) do={
        :log info "$ddnsprovname: Sending UPDATE!"
         /tool fetch address=$ddnsprovaddress src-path=$str mode=http user=$ddnsuser password=$ddnspass dst-path=("/DDNS-".$ddnsprovname.".".$ddnshost)
  }
  :delay 1
  :set str [/file find name="DDNS-$ddnsprovname.$ddnshost"];
  /file remove $str
  :set ddnslastip $ddnsip
}

#:log info "DDNS Update script executed successfully."