Dynamic DNS Update Script for ChangeIP behind NAT

From MikroTik Wiki
Revision as of 01:15, 13 October 2011 by Jorgeamaral (talk | contribs)
Jump to: navigation, search

This script is intended to update a ChangeIP.com Dynamic DNS account when your device is behind nat.

You need to set your username, password and hostname.

This was tested successfully on RouterOS 5.7.

You may copy and paste the script below into the terminal window to import a script.

  1. oct/13/2011 00:51:52 by RouterOS 5.7

/system script add name=DDNS policy=\

   ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
   source="# Please configure vars\r\
   \n:local user \"YourUser\"\r\
   \n:local pass \"YourPass\"\r\
   \n:local host \"FREEHOSTNAME.TOUPDATE.TLD\"\r\
   \n# Start script\r\
   \n:global lastwanip;\r\
   \n:if ([ :typeof \$lastwanip ] = \"nothing\" ) do={ :global lastwanip 0.0.\
   0.0 };\r\
   \n:local wanip [:resolve \$host];\r\
   \n:if ( \$wanip != \$lastwanip ) do={\r\
   \n\t/tool fetch mode=http address=\"checkip.dyndns.org\" src-path=\"/\" ds\
   t-path=\"/dyndns.checkip.html\"\r\
   \n\t:local result [/file get dyndns.checkip.html contents]\r\
   \n\t:local resultLen [:len \$result]\r\
   \n\t:local startLoc [:find \$result \": \" -1]\r\
   \n\t:set startLoc (\$startLoc + 2)\r\
   \n\t:local endLoc [:find \$result \"</body>\" -1]\r\
   \n\t:local currentIP [:pick \$result \$startLoc \$endLoc]\r\
   \n\t:set lastwanip \$currentIP;\r\
   \n\t:put [/tool dns-update name=\$host address=\$currentIP key-name=\$user\
   \_key=\$pass ]\r\
   \n}"