Send Dynamic IP Address to email – Mikrotik script

The method to send dynamic IP Address to email is the ideal solution of providing the latest IP information. Dynamic IP address changes from time to time, so Mikrotik has the perfect solution to this matter.

To send dynamic IP Address to email, we need to follow some steps. First of all, we have to create some general configurations: to configure mikrotik mail, to create a system script for sending email with IP Address info etc.

Let’s say we have two email addresses in Gmail and router with dynamic IP Address is in your office. First email address is markoffice@gmail.com and second email is markhome@gmail.com.

So, first let’s configure email in Mikrotik Router OS.

  1. Open Winbox and login to the router.
  2. Click Tools then click Email.
  3. In Server: enter ip address 74.125.196.108.
  4. Enter port  587.
  5. Start TLS, choose Yes.
  6. In the From field enter <markoffice@gmail.com>.
  7. In User field enter markoffice@gmail.com.
  8. Below enter Gmail password for email: markoffice@gmail.com.

 

Now we need a script that detects Dynamic IP from a specific Interface, and the same script sends the email to: markhome@gmail.com. 

In this case Dynamic IP is located in the interface called Wan. So, let’s create a script like this below.

  1. Click System, click Script.
  2. Enter name: my_dynamic_ip  for new script.
  3. Copy this code and paste in the Script field, click OK.

:local theaddr [/ip address get [find interface="Wan" disabled=no] address]
:local myipaddr [:put [:pick $theaddr 0 [:find $theaddr "/" ] ] ]
:local myintnm [/system identity get name]
:log warning "Dynamic IP Address: $myintnm: $myipaddr"
/ip dns static set address=$myipaddr name=router numbers=[find name="router"]
/tool e-mail send to="markhome@gmail.com" subject="Your_Dynamic_IP_Adress $myintnm - current IP
address: $theaddr" body="Router $myintnm Your_Dynamic_IP_Adress: $theaddr

mikrotik ip script

You can test this config by clicking Run Script. If you receive an email from your router, the config is working fine.

Create a scheduler to run script everyday at 20:00.

  1. Click System then click Scheduler.
  2. Clcik Add.
  3. Enter the correct information in all the fields below.
  4. Name: ip-script-run-daily
  5. Start Date: Jan/01/2018
  6. Start Time:00:00:00
  7. Interval: 1d 00:00:00
  8. On Event, Enter the name of script: my_dynamic_ip
  9. Click OK.

 

You can configure the router to send emails with new IP Address when the internet is interrupted or when your IP address is replaced by your ISP server.

All you need to do is find an IP address that is always active. The router will ping that IP every 5 seconds. At the moment when there is a ping Time Out for about 1000 ms, you will receive the email with the last IP Address.

You can do this through Netwatch.

  1. Click Tool, click Netwatch then click Add.
  2. In Host tab enter the correct information.
  3. Host: Enter an IP Address that is always active.
  4. Interval:00:00:05
  5. Timeout:1000
  6. In UP tab enter the name of IP script: my_dynamic_ip
  7. In Down tab enter: log error message=”Internet disconnected”
  8. Click OK.

 

So it was for this matter. I know, it’s a short text to read but, it’s too long to write.

Contact us: info@indexofapps.com