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.
In this case we did an experiment. We have a router in the office which we want to control from home. Let’s say we have two email addresses in Gmail and the router with dynamic IP Address is in your office. First email address is email@example.com and second email is firstname.lastname@example.org.
So we want to put the email email@example.com in the router. The router will use this email to send IP address information to the email: firstname.lastname@example.org.
Below enter Gmail password for email: email@example.com.
If the email is not sent go to Google account and allow Mikrotik access to email.
How to change security settings in Google Account to allow the router to use the Gmail:
Go to https://myaccount.google.com/security. On Less secure app access section switch to On, (Use another device to change account security settings).
Open warning email with subject Critical security alert, click Check activity then click Yes, it was me.
I want to be clear: This action makes your account less secure, but it’s the only way it works.
Now we need a script that detects Dynamic IP from a specific Interface, and the same script sends the email to: firstname.lastname@example.org.
How to create a script on the router to detect and send us IP Address information:
In this case Dynamic IP is located in the interface called Wan. So, let’s create a script like this below.
Click System, click Script.
Enter name: my_dynamic_ip for new script.
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 "Current dynamic IP address $myintnm: $myipaddr"
/ip dns static set address=$myipaddr name=router numbers=[find name="router"]
/tool e-mail send to="email@example.com" subject="Router $myintnm - current IP
address: $theaddr" body="Router $myintnm current dynamic IP: $theaddr"
Replace "Wan" with your interface name used for internet access.
Replace "firstname.lastname@example.org" with your email.
You can test this config by clicking Run Script. If you receive an email from your router, the config is working fine.
How to create a scheduler to run script everyday at 20 : 00:
Click System then click Scheduler.
Enter the correct information in all the fields below.
Start Date: Jan/01/2018
Interval: 1d 00:00:00
On Event, Enter the name of script: my_dynamic_ip
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.
How to force the router to send us IP Address info each time the IP Address changes:
Click Tool, click Netwatch then click Add.
In Host tab enter the correct information.
Host: Enter an IP Address that is always active.
In UP tab enter the name of IP script: my_dynamic_ip
In Down tab enter: log error message=”Internet disconnected”
So it was for this matter. I know, it’s a short text to read but, it’s too long to write.