/system script
add name=ChangeIP owner=admin policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="#\
    \_Dynamic DNS Update Script\r\
    \n# Modificado por Marcelo Medeiros, ChangeIP.com\r\
    \n#11042018 Testado em RouterOS 6.41.3\r\
    \n\r\
    \n# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\
    \n# EDITE SUAS CONFIGURACOES AQUI ChangeIP.com\r\
    \n# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\
    \nip address print file=lista_ips\r\
    \n:global ddnsuser "seu usuario changeip"\r\
    \n:global ddnspass "sua senha"\r\
    \n:global ddnshost "seu hostname.changeip.net"\r\
    \n:global ddnsinterface "Interface EtherX"\r\
    \n:delay 2s\r\r\
    \n:global systemID [/system identity get name]\r\r\
    \n:global RB [/system routerboard get model]\r\r\
    \n:global versionID [/system resource get version]\r\
    \n:global IP [/ip cloud get public-address]\r\r\
    \n:global data [/system clock get date]\r\r\
    \n:global hora [/system clock get time]\r\r\
    \n:global version [/system resource get version]\r\
    \n:global ddnsinterface "Interface EtherX"\r\
    \n:global ddnsip \$IP\r\r\
    \n/tool e-mail send to=seu endereco de 
[email protected] subject=\\\r\
    \n"\$systemIDdia\$data as \$hora, \$version, \$systemID  IP:\$IP"\\\r\
    \nfile="lista_ips.txt" body="Envio automatico dos Ips servidor de \\\r\
    \r\
    \n \$systemID IP:\$IP RB modelo \$RB versao \$versionID realizado\\\r\r\
    \nas \$hora de \$data  \$ddnsinterface."\r\
    \n# Change ddnsport to 8245 to bypass proxy.\r\
    \n:local ddnsport 80\r\
    \n\r\
    \n# Do not edit anything below this line. You have been warned.\r\
    \n# Abusive updates to the system will cause firewall blocks.\r\
    \n\r\
    \n# Please be considerate and\r\
    \n# do not let this script run more than once per 3-5 minutes.\r\
    \n\r\
    \n:log info "DDNS: Starting."\r\
    \n\r\
    \n# Initialize checkpoint\r\
    \n:global ddnscheckpoint\r\
    \n:if ([:typeof \$ddnscheckpoint] = "time") do={\r\
    \n\t:log info ("DDNS: Last check was " . ([/system clock get time] - \$d\
    dnscheckpoint))\r\
    \n} else={\r\
    \n\t:log info "DDNS: Cannot determine checkpoint, set now."\r\
    \n\t:global ddnscheckpoint ( [/system clock get time] - 1d )\r\
    \n}\r\
    \n\r\
    \n# Get the current IP\r\
    \n:if ([/system clock get time] - \$ddnscheckpoint > [:totime 180s] || [/s\
    ystem clock get time] - \$ddnscheckpoint < [:totime 0s]) do={\r\
    \n :log info "DDNS: Performing remote IP detection."\r\
    \n /tool fetch address="ip.changeip.com" host="ip.changeip.com" src-pa\
    th=("/\?" . [/int eth get 0 mac-address ]) dst-path="ip.changeip.com.tx\
    t" mode=http port=\$ddnsport\r\
    \n :global ddnscheckpoint [/system clock get time]\r\
    \n} else={\r\
    \n :log info "DDNS: Please be considerate and wait a few seconds longer.\
    "\r\
    \n :break\r\
    \n}\r\
    \n\r\
    \n# Parse the IP address received from fetch script.\r\
    \n\t:global ddnslastip\r\
    \n\t:local html [/file get "ip.changeip.com.txt" contents]\r\
    \n\t:local ddnsip [:pick \$html ([:find \$html "<!--IPADDR="] + 11) [:fi\
    nd \$html "-->"] ]\r\
    \n\r\
    \n# Is it a valid IP and is it different than the last one\?\r\
    \n\t:if ([:typeof [:toip \$ddnsip]] = "ip" AND \$ddnsip != \$ddnslastip \
    ) do={\r\
    \n\t\t:log info "DDNS: Sending UPDATE with \$ddnsip"\r\
    \n\t\t:log info [/tool dns-update name=\$ddnshost address=\$ddnsip key-nam\
    e=\$ddnsuser key=\$ddnspass ]\r\
    \n\t\t:global ddnslastip \$ddnsip\r\
    \n\t} else={\r\
    \n\t\t:log info "DDNS: No update required."\r\
    \n\t}\r\
    \n}\r\
    \n"