Difference between revisions of "Dynamic DNS Update Script for Hurricane Electric DNS"

From MikroTik Wiki
Jump to: navigation, search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
This script will update the IP address on ([http://dns.he.net Hurricane Electric DNS service]).
+
This script will update the IP address on [http://dns.he.net Hurricane Electric DNS service].
  
 
It updates the A/AAAA record so both IPv4 and IPv6 can be supplied.
 
It updates the A/AAAA record so both IPv4 and IPv6 can be supplied.
Line 43: Line 43:
 
:log info ("Updating DDNS IPv4 address" . " Client IPv4 address to new IP " . $ipv4addr . "...")
 
:log info ("Updating DDNS IPv4 address" . " Client IPv4 address to new IP " . $ipv4addr . "...")
  
/tool fetch url="http://$ddnshost:$key@$updatehost/nic/update?hostname=$ddnshost&myip=$ipv4addr" dst-path=$outputfile
+
/tool fetch url="http://$ddnshost:$key@$updatehost/nic/update?hostname=$ddnshost&myip=$ipv4addr" \
 +
dst-path=$outputfile
 
                                
 
                                
 
:log info ([/file get ($outputfile) contents])
 
:log info ([/file get ($outputfile) contents])
 
/file remove ($outputfile)
 
/file remove ($outputfile)
 
</pre>
 
</pre>
 +
 +
Note: The above script works with ROS 3.x. For the 5.x a minor modification for the fetch command is needed:
 +
<pre>
 +
/tool fetch mode=http url="http://$ddnshost:$key@$updatehost/nic/update?hostname=$ddnshost&myip=$ipv4addr" \
 +
dst-path=$outputfile
 +
</pre>
 +
 +
[[Category: Scripting]]

Latest revision as of 19:03, 4 March 2012

This script will update the IP address on Hurricane Electric DNS service.

It updates the A/AAAA record so both IPv4 and IPv6 can be supplied.


It uses the fetch command with the url= parameter. Check that your version of RouterOS -> /tool fetch supports this option.


The following URL to supply update information is used:

  • For auto IP detection:
http://dyn.example.com:password@dyn.dns.he.net/nic/update?hostname=dyn.example.com
  • For manually setting the IP address:
http://dyn.example.com:password@dyn.dns.he.net/nic/update?hostname=dyn.example.com&myip=192.168.0.1

For more information, see this link: [1]


The script:

# Update Hurricane Electric DDNS IPv4 address


:local ddnshost "<dyndnshost>"
:local key "key"
:local updatehost "dyn.dns.he.net"
:local WANinterface "<if>"
:local outputfile ("HE_DDNS" . ".txt")

# Internal processing below...
# ----------------------------------
:local ipv4addr

# Get WAN interface IP address
: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)
}

:log info ("Updating DDNS IPv4 address" . " Client IPv4 address to new IP " . $ipv4addr . "...")

/tool fetch url="http://$ddnshost:$key@$updatehost/nic/update?hostname=$ddnshost&myip=$ipv4addr"  \
dst-path=$outputfile
                              
:log info ([/file get ($outputfile) contents])
/file remove ($outputfile)

Note: The above script works with ROS 3.x. For the 5.x a minor modification for the fetch command is needed:

/tool fetch mode=http url="http://$ddnshost:$key@$updatehost/nic/update?hostname=$ddnshost&myip=$ipv4addr" \
dst-path=$outputfile