#Email Params
:local from [/tool e-mail get user];
:local toList {“syakir.jbgroup@gmail.com”};
:local sendEmail 0; # 1=Enable 0=Disable
#Telegram Params
:local botAPI “760495160:AAFEOmP6WZ_qs3vhZjng0ADkYd6Z1Qrfe14”; #API RouterMikrotikBot
:local chatID {“412874053”;};
:local sendTelegram 1; # 1=Enable 0=Disable
#Interface Params
:local PPPoEInterfaceList {“PPPoE-ISP1”;};
#Declare Variable
:local LastIP “”;
:local LastCharacter 0;
:local currentIP “”;
:local checkIP “”;
:local Message “”;
:local DNSName “”;
:local DNSStatus “”;
:local DNSAddress “”;
:local xdate [/system clock get date];
:local xtime [/system clock get time];
:foreach PPPoEInterface in=$PPPoEInterfaceList do={
#Find LastIP
foreach i in=([/log find where message “LastIP_$PPPoEInterface”]) do={
:set $LastIP [/log get $i message];
}
:set $LastCharacter ([:find $LastIP “:” -1]);
:set $LastCharacter ($LastCharacter + 1);
:set $LastIP [:pick $LastIP $LastCharacter 50];
#Find CurrentIP
:set currentIP [/ip address get [find interface=”$PPPoEInterface”] address];
:set currentIP [:pick $currentIP 0 [:find $currentIP “/” -1]];
:set checkIP [:pick $currentIP 0 [:find $currentIP “.” -1]];
#Jika mendapat IP Private
:if ($checkIP = “10”) do={
/log info “LastIP_$PPPoEInterface:$currentIP”;
:delay 10s;
/log error “$PPPoEInterface connection restored with assigned ip address $currentIP. Restarting Connection …”;
#sendMessage to Email
:if ($sendEmail = “1”) do={
:foreach to in=$toList do={
/tool e-mail send to=”$to” from=”$[/system identity get name] <$from>” subject=”$[/system identity get name] $PPPoEInterface Status” \
body=”$PPPoEInterface connection restored with assigned ip address $currentIP. Restarting Connection …”
}
}
#sendMessage to Telegram
:if ($sendTelegram = “1”) do={
:set Message “<b>.: $[/system identity get name] :.</b> %0A$PPPoEInterface connection restored with assigned ip address $currentIP. %0A<b>Restarting Connection …</b> %0A%0A$xdate | $xtime WIB”
:foreach SendingChatID in=$chatID do={
/tool fetch “https://149.154.167.220/bot$botAPI/sendMessage?chat_id=$SendingChatID&parse_mode=HTML&text=$Message” keep-result=no
}
}
:delay 10s;
/interface pppoe-client disable $PPPoEInterface;
:delay 10s;
/interface pppoe-client enable $PPPoEInterface;
} else={
#Jika LastIP = currentIP hanya menambahkan log
if (“$LastIP” = “$currentIP”) do={
/log info “LastIP_$PPPoEInterface:$currentIP”;
/ip cloud force-update;
} else={
#Jika mendapat sudah mendapat IP Public
/log info “LastIP_$PPPoEInterface:$currentIP”;
:delay 10s;
/ip cloud force-update;
:delay 30s;
:set DNSName [/ip cloud get dns-name];
:set DNSStatus [/ip cloud get status];
:set DNSAddress [/ip cloud get public-address];
/log warning “$PPPoEInterface connection restored with assigned ip address $currentIP. (DDNS Status: $DNSStatus | $DNSName)”;
#sendMessage to Email
:if ($sendEmail = “1”) do={
:foreach to in=$toList do={
/tool e-mail send to=”$to” from=”$[/system identity get name] <$from>” subject=”$[/system identity get name] $PPPoEInterface Status” \
body=”$PPPoEInterface connection restored with assigned ip address $currentIP. (DDNS Status: $DNSStatus | $DNSName)”;
}
}
#sendMessage to Telegram
:if ($sendTelegram = “1”) do={
:set Message “<b>.: $[/system identity get name] :.</b> %0A$PPPoEInterface connection restored with assigned ip address $currentIP. %0A%0A<b>.: IP Cloud Information :.</b>%0AStatus: $DNSStatus %0APublic Address: $DNSAddress %0ADNS Name: $DNSName %0A%0A$xdate | $xtime WIB”
:foreach SendingChatID in=$chatID do={
/tool fetch “https://149.154.167.220/bot$botAPI/sendMessage?chat_id=$SendingChatID&parse_mode=HTML&text=$Message” keep-result=no
}
}
}
}
#Clear Variable Before Next Interface
:set LastIP “”;
:set LastCharacter 0;
:set currentIP “”;
:set checkIP “”;
:set Message “”;
:set DNSName “”;
:set DNSStatus “”;
:set DNSAddress “”;
}
![]() |
Parameter Email |
![]() |
Parameter Telegram |
![]() |
Parameter Interface |
![]() |
Membuat Script |
![]() |
Aktifkan Script |
![]() |
Hasil |