Difference between revisions of "Dynamic DNS Update Script for EveryDNS"

From MikroTik Wiki
Jump to: navigation, search
(Note about non-ssl, password safety.)
Line 9: Line 9:
 
:local eduser "USERNAME"
 
:local eduser "USERNAME"
 
:local edpass "PASS"
 
:local edpass "PASS"
:local eddomain "DYNAMIC.DOMAIN"  
+
:local eddomain "mydomain.com"  
 
:local edinterface "INTERFACE_NAME"
 
:local edinterface "INTERFACE_NAME"
  
Line 21: Line 21:
  
 
:local ip [ /ip address get [/ip address find interface=$edinterface ] address ]
 
:local ip [ /ip address get [/ip address find interface=$edinterface ] address ]
 +
# TODO: netmask can be more than 2 characters
 
:local edip [ :pick $ip 0 ([:len $ip]-3)]
 
:local edip [ :pick $ip 0 ([:len $ip]-3)]
 
:if ([ :typeof $edip ] = nil ) do={
 
:if ([ :typeof $edip ] = nil ) do={
   :log info ("EveryDNS: No ip address on " . $edinterface . ".")
+
   :log info ("EveryDNS: No ip address on $edinterface .")
 
} else={
 
} else={
  
 
   :if ($edip != $edlastip1) do={
 
   :if ($edip != $edlastip1) do={
  
     :log info ("EveryDNS: " . $eddomain . " -> " . $edip)
+
     :log info ("EveryDNS: $eddomain -> $edip")
     :local str ("/index.php?ver=0.1&ip=" . $edip . "&domain=" . $eddomain)
+
     :local str "/index.php?ver=0.1&ip=$edip&domain=$eddomain"
     /tool fetch address=66.240.223.182 src-path=$str user=$eduser password=$edpass dst-path=("/EveryDNS.".$eddomain)
+
     /tool fetch url="http://dyn.everydns.net/$str" mode=http user=$eduser password=$edpass dst-path=("/EveryDNS.".$eddomain)
 
     :delay 1  
 
     :delay 1  
 
     :local str [/file find name=("EveryDNS.".$eddomain)]
 
     :local str [/file find name=("EveryDNS.".$eddomain)]
    /file remove $str
+
# do not delete file. If something is wrong, useful information can be found in it's contents.
 +
#    /file remove $str
 
     :global edlastip1 $edip
 
     :global edlastip1 $edip
  
Line 44: Line 46:
 
You should setup this script, so using username and password as you registered at http://www.everydns.com/. Dynamic domain should be name of sub-domain that you want to be updated automaticly ex. r.paxy.in.rs . Interface name field should be exact name of interface that you want to monitor for IP change, in my case it is PPPoE type interfaces.<br>
 
You should setup this script, so using username and password as you registered at http://www.everydns.com/. Dynamic domain should be name of sub-domain that you want to be updated automaticly ex. r.paxy.in.rs . Interface name field should be exact name of interface that you want to monitor for IP change, in my case it is PPPoE type interfaces.<br>
 
<br>If you want to monitor more then one interface, create another script, fill username and pass, change sub-domain to another sub-domain name, and change interface that monitor IP address. Because of spoofing protection, you have to change variable "edlastip1" to any other name, like "edlastip2" in whole script.<br>
 
<br>If you want to monitor more then one interface, create another script, fill username and pass, change sub-domain to another sub-domain name, and change interface that monitor IP address. Because of spoofing protection, you have to change variable "edlastip1" to any other name, like "edlastip2" in whole script.<br>
Script use server with DNS name dyn.everydns.net, which is currently resolved to 66.240.223.182, if EveryDNS change dyndns parameters, just resolve right server DNS and update script.<br>
+
Script use server with DNS name dyn.everydns.net.<br>
 
<br>
 
<br>
 
All what is left now is to make scheduler to run this or those scripts every minute.
 
All what is left now is to make scheduler to run this or those scripts every minute.
Line 53: Line 55:
 
<br>
 
<br>
 
Happy hacking ...
 
Happy hacking ...
 +
<br />
 +
<br />
 +
Modified to work with version 3.23
  
 
[[Category:Scripting]]
 
[[Category:Scripting]]

Revision as of 13:17, 27 April 2009

This script allow you to easily maintain dynamic updates at EveryDNS free DNS server.
First you have to setup an account at http://www.everydns.com/, and with few steps create dynamic domain. After that you have to setup EasyDNS servers NS DNS parameters at domain seller site.

Next script is build with target to update DNS with two or more PPPoE connection with dynamics IP addresses.

# Define user variables
# Please NOTE that your username and password will be sent cleartext across the internet!
:local eduser "USERNAME"
:local edpass "PASS"
:local eddomain "mydomain.com" 
:local edinterface "INTERFACE_NAME"

# 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 ip [ /ip address get [/ip address find interface=$edinterface ] address ]
# TODO: netmask can be more than 2 characters
:local edip [ :pick $ip 0 ([:len $ip]-3)]
:if ([ :typeof $edip ] = nil ) do={
   :log info ("EveryDNS: No ip address on $edinterface .")
} else={

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

    :log info ("EveryDNS: $eddomain -> $edip")
    :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 
    :local str [/file find name=("EveryDNS.".$eddomain)]
# do not delete file. If something is wrong, useful information can be found in it's contents.
#    /file remove $str
    :global edlastip1 $edip

  } 

}
# Coded by Paxy

You should setup this script, so using username and password as you registered at http://www.everydns.com/. Dynamic domain should be name of sub-domain that you want to be updated automaticly ex. r.paxy.in.rs . Interface name field should be exact name of interface that you want to monitor for IP change, in my case it is PPPoE type interfaces.

If you want to monitor more then one interface, create another script, fill username and pass, change sub-domain to another sub-domain name, and change interface that monitor IP address. Because of spoofing protection, you have to change variable "edlastip1" to any other name, like "edlastip2" in whole script.
Script use server with DNS name dyn.everydns.net.

All what is left now is to make scheduler to run this or those scripts every minute.

/system scheduler add name=EveryDNS1 interval=00:01 on-event="/system script run everyDns1\r\n/system script run everyDns2"


Happy hacking ...

Modified to work with version 3.23