Difference between revisions of "Ros3 Dyn DNS"

From CTWUG Wiki
Jump to: navigation, search
(Fixed formatting)
(Updates Script)
Line 15: Line 15:
 
==Script==
 
==Script==
 
<pre><nowiki>
 
<pre><nowiki>
# Define User Variables
+
# MyDDns International Account
:global ddnsuser "username"
 
:global ddnspass "password"
 
:global ddnshost "Host Name"
 
  
# Define Global Variables
+
# Local user variables
:global ddnsip
+
:local DnsUser "enter your MyDDns username here"
:global ddnslastip
+
:local DnsPass "enter your MyDDns password here"
:if ([ :typeof $ddnslastip ] = nil ) do={ :global ddnslastip "0" }
+
:local DnsHost "enter your MyDDns hostname here"
 +
:local DnsInterface "enter your PPPoE interface name here"
  
:global ddnsinterface
+
# Global user variables
:global ddnssystem ("mt-" . [/system package get system version] )
+
# if you have another PPPoE account with this script you need to change LastDnsIpInter to something unique; search/replace
 +
:global LastDnsIpInter
  
 +
:if ([ :typeof $LastDnsIpInter ] = nil) do={ :global LastDnsIpInter "0"}
  
# Define Local Variables
+
# Get the current Ip Address
:local int
+
:local DnsIp [/ip address get [/ip address find interface=$DnsInterface] address ]
 
  
# Loop thru interfaces and look for ones containing
+
# Check for updates
# default gateways without routing-marks
+
:if ([ :typeof $DnsIp ] = nil ) do={
:foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes ] do={
+
   :log info ("DynDns: No Ip address present on ". $DnsInterface )
  :if ([:typeof [/ip route get $int routing-mark ]] != str ) do={
 
    :global ddnsinterface [/ip route get $int interface]
 
   }
 
}
 
 
 
# Grab the current IP address on that interface.
 
:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface ] address ]
 
 
 
 
# Did we get an IP address to compare?
 
:if ([ :typeof $ddnsip ] = nil ) do={
 
  :log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")
 
 
} else={
 
} else={
   
+
  :local NewIp [ :pick $DnsIp 0 [ :find $DnsIp "/" ] ]  
 
+
   :if ($NewIp != $LastDnsIpInter) do={
   :if ($ddnsip != $ddnslastip) do={
+
     :log info ("DynDns: ". $DnsInterface ." Sending update.")
+
     :local DnsResult ( [ :put [ /tool dns-update name=$DnsHost address=$NewIp key-name=$DnsUser key=$DnsPass ] ] )
 
+
     :global LastDnsIpInter $NewIp
     :log info "DDNS: Sending UPDATE!"
+
   } else={
     :log info [ :put [/tool dns-update name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip "/"] ] key-name=$ddnsuser key=$ddnspass ] ]
+
# Uncomment the line below if you want to see when updates aren't needed 
     :global ddnslastip $ddnsip
+
#    :log info "DynDns: ($DnsInterface) No update needed"
 
 
 
   } else={  
 
    :log info "DDNS: No update required."
 
 
   }
 
   }
 
 
 
}
 
}
 
 
# End of script
 
:log info "DDNS: End"
 
 
</nowiki></pre>
 
</nowiki></pre>

Revision as of 18:44, 18 July 2009

Info

The following script should be created when you wish to update your ChangeIP.com Dynamic DNS account. Once created you should schedule this to run once in a while. The :global variables should be edited to include your unique username and password, interface name, etc. The script here should allow auto-detection of the default gateways interface name. This script below can be used if you have more than 1 WAN connection, but only 1 is active at a time.

This script will work as is, just navigate to System/Scripts and run it. This particular script works good with a 5 minute interval to update your Dynamic DNS with a scheduler.

Setup

For this script to function correctly, there are a few things that will need to be setup. Not necessary, but always good to have in place.

Enhancements

  • Check out Dynamic DNS Schedule to create a schedule, that will run the script at a predefined period.

Script

# MyDDns International Account

# Local user variables
:local DnsUser "enter your MyDDns username here"
:local DnsPass "enter your MyDDns password here"
:local DnsHost "enter your MyDDns hostname here"
:local DnsInterface "enter your PPPoE interface name here"

# Global user variables
# if you have another PPPoE account with this script you need to change LastDnsIpInter to something unique; search/replace
:global LastDnsIpInter

:if ([ :typeof $LastDnsIpInter ] = nil) do={ :global LastDnsIpInter "0"}

# Get the current Ip Address
:local DnsIp [/ip address get [/ip address find interface=$DnsInterface] address ]

# Check for updates
:if ([ :typeof $DnsIp ] = nil ) do={
  :log info ("DynDns: No Ip address present on ". $DnsInterface )
} else={
  :local NewIp [ :pick $DnsIp 0 [ :find $DnsIp "/" ] ]  
  :if ($NewIp != $LastDnsIpInter) do={
    :log info ("DynDns: ". $DnsInterface ." Sending update.")
    :local DnsResult ( [ :put [ /tool dns-update name=$DnsHost address=$NewIp key-name=$DnsUser key=$DnsPass ] ] )
    :global LastDnsIpInter $NewIp
  } else={
# Uncomment the line below if you want to see when updates aren't needed  
#    :log info "DynDns: ($DnsInterface) No update needed"
  }
}