Here is a script that will update the ChangeIP.com dynamic DNS system whenever your DHCP interface changes IP addresses.
* This script checks for changed IPs each 30 seconds.
* This script will run with no one logged into the router.
* This script needs to be modified to fit your environment. See below:
Step 1.
Copy this script into Notepad or other editor.
Step 2.
Modify the values in the 'ddnsInit' script to fit your particular environment.
Code: Select all
u = Your Username on ChangeIP.com
p = Your Password on ChangeIP.com
s = System Name. You can leave this as default, this is for our stats.
h = Hostname to update. *1 means set 1 - many hosts at once.
dhcpInterface = This is the interface name on Mirkotik that you want to monitor.
ddnsProxyEmail = The address to send the updates to. Leave this as default.
ddnsFromEmail = The email address you want the results emailed to upon update.
ddnsSmtpServer = The default is our mail server. Feel free to use any mail server capable of delivering mail to us reliably.
Save this script somewhere for later use. Now copy and paste the script as is into the command line environment of Mikrotik. This will remove the previous scripts, if any, and enter the new ones.
Step 4.
Let the script run for 1 minute at least. You should receive an email with the results of the update.
This script should be complete. There are a few items that we are completing on the backend proxy service, ie: cleaned up result email, etc. We will also, if anyone wishes, create a proxy that can be used for any other DDNS providers. how nice right? We like you to use ChangeIP.com, but if you need to get this going asap before you switch over we can help you.
Here is the script. Paste into terminal window once modified for your credentials.
Code: Select all
/system scheduler remove ddnsJob
/system script remove ddnsCheck
/system script remove ddnsInit
/system script remove ddnsReset
/system script remove ddnsSendUpdate
/system script add name="ddnsInit" source={
:log message="ddnsInit: Creating Dynamic DNS update system."
:global u
:set u "USERID"
:global p
:set p "PASSWORD"
:global s
:set s "Mikrotik"
:global h
:set h "*1"
:global dhcpInterface
:set dhcpInterface "ether0"
:global ddnsProxyEmail
:set ddnsProxyEmail "ddnsUpdate@ChangeIP.com"
:global ddnsFromEmail
:set ddnsFromEmail "youremail@domain.tld"
:global ddnsSmtpServer
:set ddnsSmtpServer "63.210.174.75"
:global a
:set a [ \
/ip address get \
[/ip address find interface=$dhcpInterface] \
address \
]
}
/system script add name="ddnsCheck" source={
:if ([/system scheduler get ddnsJob run-count]<=1) do={
/system script run ddnsInit
}
:global temp
:global b
:set temp $a
:set b [ \
/ip address get \
[/ip address find interface=$dhcpInterface] \
address \
]
:if ($temp != $b) do={
:log message="ddnsCheck: Found new IP address."
/system script run ddnsSendUpdate
:set a $b
}
}
/system script add name="ddnsSendUpdate" source={
:log message=("ddnsSendUpdate: Sending Dynamic DNS smtp update to " . $ddnsSmtpServer)
/tool e-mail send \
to=$ddnsProxyEmail \
from=$ddnsFromEmail \
server=$ddnsSmtpServer \
subject="New Dynamic IP" \
body=("u=" . $u . "&p=" . $p . "&hostname=" . $h . "&system=" . $s . "&myip=" . $b)
}
/system script add name="ddnsReset" source={
:log message="ddnsReset: Resetting global values."
/system scheduler set ddnsJob run-count=0
:unset u
:unset p
:unset s
:unset h
:unset dhcpInterface
:unset ddnsProxyEmail
:unset ddnsFromEmail
:unset ddnsSmtpServer
:unset a
:unset b
:unset temp
}
/system scheduler add name=ddnsJob interval=30s on-event=ddnsCheck
http://www.ChangeIP.com/
Thanks,
Sam Norris
ChangeIP.com