Page 1 of 1

Dynamic DNS Update Script (SMTP Proxy)

Posted: Sat Jul 31, 2004 2:26 am
by changeip
*** BETA Release ***

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.
  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.
Step 3.
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.
/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
For support of this script as well as any other questions you can send an email to Support@ChangeIP.com. We'd love to get a few people setup to beta test this ... please email us if you are helping out.

http://www.ChangeIP.com/

Thanks,
Sam Norris
ChangeIP.com

email

Posted: Mon Aug 09, 2004 6:34 pm
by schickb
I have been working with this for some time... I emailed your support, got some advise but then the line went cold. so for the benefit of everyone I thought I would post my finding here.


1) If you are using the default pppoe name it won't work. The script dosn't like 'PPPoe-out1'. Chang the name to something without the '-' (PPPoe works fine)

2) in the line with the '*1' This caused an error on my system. The changeip guys suggested using '-1' This worked.

Being new to Mikrotik, I am unable to send the email. The system says it times out. Am I missing a basic setup step?

Posted: Mon Aug 09, 2004 6:41 pm
by changeip
Hello,

I wonder if its possible your ISP is blocking port 25 outbound. Can you try changing the outgoing smtp server in the script to your ISPs SMTP server, or whichever server that you can reliably deliver mail with? I guess if you really needed to you could add an outgoing masquerade on port 25 to 5072 to our server - this would get around any port blocks your ISP has placed on you. If you need help configuring this let me know, I'll help you out.

I will post a modified script here shortly that will fix the *1 -1 problem, I didn't realize Mikrotik would have a problem with the * character in a string field.

Can you try something out - try from a machine inside your network the following command: 'telnet smtp.changeip.com 25' and see if you get response header. If that does not work, try 'telnet smtp.changeip.com 5072' and see if that works. If the second works let me know and we can setup a masquerade rule that will translate that outgoing connection to port 5072 ( I think )

Sam

update

Posted: Mon Aug 09, 2004 7:56 pm
by schickb
No blocked ports. The telnet command returns info.

help

Posted: Tue Aug 17, 2004 5:47 am
by schickb
inside the network I can ping... however if I use the ping command from the router it does not work. What am I missing (firewall rule?)

update

Posted: Tue Aug 17, 2004 6:06 am
by schickb
I got the pings to work, however still get an email timed out....

Posted: Wed Dec 08, 2004 7:45 pm
by changeip
Here is an updated script to perform dynamic dns updates from the Mikrotik router. Changes include finding the dhcp interface automatically, performing a dns lookup to the smtp servername, and a few other clean up items.
# Dynamic DNS Update Script v1.1
# ------------------------------
# This script will perform automatic dynamic dns updates on the Mikrotik
# router platform.  (http://www.mikrotik.com/)  Since Mikrotik does not
# support sending http requests we have created a smtp -> ddns proxy service
# which will take the http URL querystring used for a dynamic dns update and
# process it via email.
# ------------------------------
# Written by Sam Norris, ChangeIP.com
# 7/31/04 - Created script.
# 12/9/04 - Made some values dynamic (smtp server, dhcp interface)
# ------------------------------
#
# Instructions:
#    There are a few variables down below that you need to configure for your
#    specific setup.  Please modify the variables in the 'ddnsInit' script to
#    reflect your specific information, ie userid, password, hostname to update.
#

# Blow away any existing script code, if necessary.
/system scheduler remove ddnsJob
/system script remove ddnsCheck
/system script remove ddnsInit
/system script remove ddnsReset
/system script remove ddnsSendUpdate

# Setup global variables needed to keep track of changing IP address.
/system script add name="ddnsInit" source={

  :log message="ddnsInit: Creating Dynamic DNS update system."

# ENTER YOUR CHANGEIP.COM USER ID HERE.
  :global u
  :set u "USERID"

# ENTER YOUR CHANGEIP.COM PASSWORD HERE.
  :global p
  :set p "PASSWORD"

  :global s
  :set s "Mikrotik"

# ENTER THE TARGET HOSTNAME TO UPDATE, *1 is Set 1.
  :global h
  :set h "*1"

  :global dhcpInterface
  :set dhcpInterface [ /ip dhcp-client get interface ]
  :log message=("ddnsInit: Found dhcp interface " . $dhcpInterface )

# EMAIL PROXY ADDRESS - DO NOT CHANGE FOR PRODUCTION.
  :global ddnsProxyEmail
  :set ddnsProxyEmail "ddnsUpdate@ChangeIP.com"

# ENTER YOUR EMAIL ADDRESS FOR CONFIRMATIONS.
  :global ddnsFromEmail
  :set ddnsFromEmail "youremail@domain.tld"

# SMTP DDNS PROXY SERVER - CHANGE ONLY IF NECESSARY (port 25 blocked?)
  :global ddnsSmtpServer
  :set ddnsSmtpServer [:resolve smtp.changeip.com]

  :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

Please post any questions or comments.

Thanks,
Sam Norris
http://www.ChangeIP.com

Posted: Tue Jan 24, 2006 4:33 pm
by savage
Does this work on 2.9? Having some issues running these on 2.9. Script does not even execute (execute count doesn't go up)..

Thanks,
Chris

Posted: Tue Jan 24, 2006 8:20 pm
by changeip
This script is for 2.8 only. 2.9 has native support for our Dynamic DNS. Please use this script for 2.9 - and schedule it to run once every few minutes.
:log info "DDNS: Begin"

:global ddns-user "YOURUSERID"
:global ddns-pass "YOURPASSWORD"
:global ddns-host "*1"
:global ddns-interface "EXACTINTERFACENAME"

:global ddns-system ("mt-" . [/system package get [/system package find name=system] version] )

:global ddns-ip [ /ip address get [/ip address find interface=$ddns-interface] address ]

:if ([ :typeof $ddns-lastip ] = nil ) do={ :global ddns-lastip 0.0.0.0/0 }

:if ([ :typeof $ddns-ip ] = nil ) do={

  :log info ("DDNS: No ip address present on " . $ddns-interface . ", please check.")

} else={

  :if ($ddns-ip != $ddns-lastip) do={

    :log info "DDNS: Sending UPDATE!"
    :log info [ /tool dns-update name=$ddns-host address=[:pick $ddns-ip 0 [:find $ddns-ip "/"] ] key-name=$ddns-user key=$ddns-pass ]
    :global ddns-lastip $ddns-ip

  } else={ 

    :log info "DDNS: No change" 

  }

}

:log info "DDNS: End" 

Thx,
Sam

Posted: Thu Mar 02, 2006 10:45 pm
by MikroManagement
I use the script to update my IP adress on my MikroTik 2.9.13 device.

Everything works... but I have 2x ADSL connections on my MikroTik and would like to update both IP addresses

I did configure the full hostname and servers, but both scripts (Interface_Name and Hostname changed) do update the SAME address on the changeip server.

Any help regarding 2x update scripts?

Posted: Thu Mar 02, 2006 10:58 pm
by changeip
The above scripts are for 2.8 - and are using a SMTP to DDNS proxy to get the addresses updated. 2.9 has Dynamic DNS for ChangeIP.com built in natively and can update much more efficiently.

Here is a URL on the 2.9 version:
http://wiki.mikrotik.com:3280/wiki/Dyna ... angeIP.com

Here is a URL for the 2.9 inbound load balancing version:
http://forum.mikrotik.com/viewtopic.php ... highlight=

If you want to setup round-robin to both of your dsl modems you can do that as well - or modify the script to send an update for each connection and its appropriate ip, however i think the first option is best.

Thanks,
Sam

Posted: Sun Mar 05, 2006 7:12 pm
by Vendég
Hello changeip,

I am trying to set up the DDNS support on my Mikrotik router, however I have the problem: telneting you there is no answer on the port 25 which you suggested to check below. I may log in through the 5072 port.

"Can you try something out - try from a machine inside your network the following command: 'telnet smtp.changeip.com 25' and see if you get response header. If that does not work, try 'telnet smtp.changeip.com 5072' and see if that works. If the second works let me know and we can setup a masquerade rule that will translate that outgoing connection to port 5072 ( I think )"

Would you help me out with a solution you mentioned above?

An other thing, when I past the scrit to my command line session and run the script in the log I find the following post:

"script error: invalid item number"

Any idea what to check?

Mikrotik v2.8.26

Posted: Sun Mar 05, 2006 7:57 pm
by changeip
Hello,

It sounds like port 25 is blocked to your router from your ISP. Is it possible to enter their SMTP server and have it forward ? Or any smtp server that will relay for you.

:global ddns-interface "EXACTINTERFACENAME"

Check the above variable and make sure the interface name is exactly as it is in mikrotik... if it can't find the interface it will give you the error you are seeing.

The 2.9 script is much more robust, are you planning on upgrading to 2.9 anytime soon ?

Thx,
Sam

Posted: Mon Mar 06, 2006 10:21 pm
by Vendég
Hello changeip,

I am useing the:

:global dhcpInterface
:set dhcpInterface [ /ip dhcp-client get interface ]
:log message=("ddnsInit: Found dhcp interface " . $dhcpInterface )

script part to get the global and it find it since it sends a message in the log. (It finds the ether0 called WAN on my router, should not I use the pppoe interface name which sits on the WAN interface?) Anyway that does not work neither, I tryed.

Is it possible to enter their SMTP server and have it forward?

I am not sure how to forward that.

Or any smtp server that will relay for you.

Maybe I will try some.

The 2.9 script is much more robust, are you planning on upgrading to 2.9 anytime soon ?

If you mean better, I will upgrade.

Thanks V.

Posted: Tue Mar 07, 2006 1:39 am
by changeip
[quote="Vendég"]If you mean better, I will upgrade.[quote]

2.9 is way ahead of 2.8 : ) I don't want you to upgrade though until you are ready, but its ddns functionality is much better. The ddns via smtp proxy was a temporary hack for 2.8 because it did not support our services yet.

Thx,
Sam

Re: Dynamic DNS Update Script (SMTP Proxy)

Posted: Wed Jun 20, 2007 1:42 pm
by satellite_dave
hi ,
I am a newbie to mikrotik scripts,
can some one pls let me know hot to schedule to mikrotik to run the scripr for 2.9 every 30 seconds.
many thanks in advance
SAT DAVE

Re: Dynamic DNS Update Script (SMTP Proxy)

Posted: Wed Jun 20, 2007 1:52 pm
by mrz
/system scheduler

add new rule and set interval to 30 seconds.

Re: Dynamic DNS Update Script (SMTP Proxy)

Posted: Wed Jun 20, 2007 2:09 pm
by satellite_dave
hi,
i really am new to this,
i copied and pasted and it came back with
no such argument (new)

How should it look to run the changeip script.

Many thanks in advance

SAT DAVE

Re: Dynamic DNS Update Script (SMTP Proxy)

Posted: Wed Jun 20, 2007 2:47 pm
by mrz
/system scheduler add interval=30s on-event="your script name here"

you should better check out manual on available commands:
http://www.mikrotik.com/testdocs/ros/2. ... eduler.php

Re: Dynamic DNS Update Script (SMTP Proxy)

Posted: Wed Jun 20, 2007 5:58 pm
by changeip
If you are using 2.9 or above please do not use this SMTP proxy version. 2.9 is much more efficient at ddns updates, search the wiki or forums to find the new script. Then, once you paste the script into the RouterOS, make a scheduler job with the name of that script. I suggest scheduling it no more than 1 time per minute, 5 minutes is normal.

Sam