Ros3 Dyn DNS

From CTWUG Wiki
Revision as of 18:22, 29 November 2009 by Witwolf (talk | contribs)

Jump to: navigation, search

Info

There are two scripts available to use. One is for ChangeIP.com or MyDDns.com, and the other for EveryDNS. Once created you should schedule this to run once in a while.

The ChangeIP.com and MyDDNS.com Script

The :local 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"
  }
}

The EveryDNS.com Script

Change all the local variables at the top of the script to your relevant EveryDNS account. This script can work with multiple interfaces. You need to setup a script for every interface. Change the edlastip1 global variable to edlastip2 for the second script, and edlastip3 for the third script etc.

# Define user variables
# Please NOTE that your username and password will be sent cleartext across the internet!
:local eduser "enter your EveryDNS username here"
:local edpass "enter your EveryDNS password here"
:local eddomain "enter your full qualifying domain here"
:local edinterface "enter the interface which you want to grab the IP from"

# Change this global variable if you want more than 1 script
:global edlastip1
:local str
:local edip
:local ip

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

:local edip [ /ip address get [/ip address find interface=$edinterface ] address ]

:if ([ :typeof $edip ] = nil ) do={
   :log info ("EveryDNS: No ip address on $edinterface .")
} else={

# strip off netmask correctly (MRz)
   :for i from=( [:len $edip] - 1) to=0 do={
      :if ( [:pick $edip $i] = "/") do={
	   :set edip [:pick $edip 0 $i];
      }
   }

  :if ($edip != $edlastip1) do={

    :log info ("EveryDNS: $eddomain -> $edip")
# use url directly and mode http (MRz)
    :local str "/index.php?ver=0.1&ip=$edip&domain=$eddomain"
    /tool fetch url="http://dyn.everydns.net/$str" mode=http user=$eduser password=$edpass dst-path=("/EveryDNS.".$eddomain)
    :delay 1

# output any error messages received from file
    :local str [/file find name="EveryDNS.$eddomain"];
    :log info [/file get $str contents];
    /file remove $str
    :global edlastip1 $edip
  }
}

Add a schedule to run this script every minute. It will only update the IP if it differs with the current domain IP.