Community discussions

MikroTik App
 
kenyloveg
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 89
Joined: Tue Jul 14, 2009 3:25 pm

Need help to modify a script

Thu Nov 19, 2020 2:08 pm

Hi guys,
Recently I'm having problems with my ISP, they are deploying NAT to save IPV4 address instead of moving to IPV6.
I used to have a script in /system/schedule to change NAT address ip.
:global new
:global old
:global status
    :set status [/interface get [/interface find  name=("pppoe-out1")] running]
    :if ($status=true) do={
     :set new [/ip address get [/ip address find dynamic=yes interface=("pppoe-out1")] address]
     :set new [:pick $new 0 ([:len $new] -3)]
     :set old [/ip firewall nat get [find comment=("src-nat")] to-addresses]
      :if  (!($new=$old)) do={
      /ip firewall nat set [/ip firewall nat find comment=("src-nat")] to-addresses=$new
       }}
       
Can someone help me modify this script, so it will also send me emails to notify me. And this email is sent out ONLY IF pppoe-out address is changed.
For example, email body should be like
email subject xxx's (defined in script) ip address is changed to 11.22.33.44, also email body with detals like system package version, running days, average CPU usage, total data usage of pppoe-out1 (including upload and download) ...etc
I've searched this forum, and found out this thread
viewtopic.php?f=9&t=111073
Thanks and have a good day.
Last edited by kenyloveg on Thu Nov 19, 2020 2:17 pm, edited 2 times in total.
 
kenyloveg
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 89
Joined: Tue Jul 14, 2009 3:25 pm

Re: Need help to modify a script

Thu Nov 19, 2020 2:14 pm

BTW, I've already setup my email settings.
/tool e-mail
set address=smtp.xxxx.net from=sender@smtpserver.net password=xxxxx port=465 start-tls=tls-only user=receiver@receivermail.net
 
pe1chl
Forum Guru
Forum Guru
Posts: 10221
Joined: Mon Jun 08, 2015 12:09 pm

Re: Need help to modify a script

Thu Nov 19, 2020 4:53 pm

Insert it in the if body (below the nat setting command):
/tool e-mail send to="yourname@yourdomain" subject="your subject" body="yourmessage"
 
nescafe2002
Forum Veteran
Forum Veteran
Posts: 897
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: Need help to modify a script

Thu Nov 19, 2020 7:00 pm

I used to have a script in /system/schedule to change NAT address ip.

Why don't you add pppoe-client to WAN interface list to take advantage of masquerade rule in default configuration?

Who is online

Users browsing this forum: No registered users and 22 guests