Notification When Public IP Address Router Changes - MikroTik Script RouterOS
Notification when the external IP address of the MikroTik router changes. Send a message to email or Telegram.
The script creates a global variable CurrentIP to store the current external IP address of the MikroTik router.
The script uses the ipify.org service API to get an external IP address.
:global CurrentIP;
:local NewIP ([/tool fetch url=http://api.ipify.org/ as-value output=user] -> "data")
:if ($NewIP != $CurrentIP) do={
# Variables
:local Time [/system clock get time];
:local Date [/system clock get date];
:local DeviceName [/system identity get name];
:local Text "New IP: $NewIP, Previous IP: $CurrentIP";
:set CurrentIP $NewIP;
# START Send Telegram Module
:local MessageText "\F0\9F\9F\A2 $DeviceName: External IP address has changed. $Text";
:local SendTelegramMessage [:parse [/system script get MyTGBotSendMessage source]];
$SendTelegramMessage MessageText=$MessageText;
#END Send Telegram Module
# START Send Email Module
:local SendTo "[email protected]";
:local Subject "\F0\9F\9F\A2 INFO: $DeviceName [$Date $Time] External IP address has changed.";
:local MessageText $Text;
:local FileName "";
:local SendEmail [:parse [/system script get SendEmailFunction source]];
$SendEmail SendTo=$SendTo TextMail=$MessageText Subject=$Subject FileName=$FileName;
# END Send Email Module
};