Page 1 of 1

WAN IP email sending script

Posted: Thu Jul 07, 2011 10:03 pm
by Eliminateur
Hello,
i need to run a script in my ROS 5.5 box that simply emails the WAN IP if it changes.
the WAN is a dhcp client standard ip

i've tried both of the scripts here: http://wiki.mikrotik.com/wiki/Sending_y ... IP_address
(changing the mail send line as i have the mail server configured globally, the line by itself can send a mail with no problem)

but it does nothing, logs no errors and sends no mail.

how can i debug this line by line or enable so more debugging?

Re: WAN IP email sending script

Posted: Thu Jul 07, 2011 11:56 pm
by SurferTim
This works for me. Change ether1 to the appropriate WAN interface if that is not it.
:global ipadd;
:local thisip [/ip address get [find where interface=ether1] address];

:if ($ipadd != $thisip) do={
    /tool e-mail send to="you@yourdomain.com" subject="ip change" body="New ip $thisip";
    set ipadd $thisip;
}
Save as checkip (just for an example).
Then test it!
/system script
run checkip
The first time you run it, and after a reboot, it will send an email because it has no memory of variable settings before a reboot, so the variable ipadd will be empty.

Run it again. If the ip has not changed, you will not get another email.

The schedule this to run every few minutes to an hour, depending on how up-to-date you need the notice.

Re: WAN IP email sending script

Posted: Fri Jul 08, 2011 8:20 pm
by Eliminateur
thanks, using your script(much simpler as well) worked like a charm!

Re: WAN IP email sending script

Posted: Mon Jul 08, 2013 4:04 pm
by Nanflexal
can we modify this to send email is one WAN interface is down.

thanks

Re: WAN IP email sending script

Posted: Tue Jul 09, 2013 2:49 am
by SurferTim
can we modify this to send email is one WAN interface is down.
It shouldn't be a problem as long as it isn't the interface the email is sent through. How do you expect to determine the interface is down? Pinging another device works ok for that.

Re: WAN IP email sending script

Posted: Sat Aug 03, 2013 8:19 am
by Reborns
SurferTim

Can you re-check script please ??? after upgrading to ROSv6 script doesn't work anymore ...

Re: WAN IP email sending script

Posted: Sat Aug 03, 2013 1:28 pm
by SurferTim
I'm using v5.25, so mine will still work.

Which v6 are you using? Another user had trouble with a script with v6.1 until he upgraded to v6.2.

Re: WAN IP email sending script

Posted: Sat Sep 12, 2015 9:09 pm
by ALX1S
Hi,

Could someone run this or a larger script in RouterOS 6.21.1?

Thanks.

Im getting an error sending some test email
Error sending e-mail <test>: abnormal termination: (timeout)

Re: WAN IP email sending script

Posted: Sun Mar 13, 2016 11:06 pm
by Ingemars
Running fine on v 6.35rc16 on RB951G-2HnD.
Thank you for posting this useful script.

Re: WAN IP email sending script

Posted: Tue Jun 13, 2017 9:31 pm
by markuswenger
Unfortunately tickt me in the scheduler intervall always a mail purely although the ip has not changed. Can it be because I have two scripts with different interfaces? I know I am already on a neuerm os 6.39.1
($ Ipadd! = $ Thisip) does not work there?
Greetings from switzerland


/system script
add name=sfp1-wan-ip-send owner=m4bwema policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":global ipadd;\
\n:local thisip [/ip address get [find where interface=sfp1-pppoe] address];\r\
\n\r\
\n:if (\$ipadd != \$thisip) do={\r\
\n /tool e-mail send to=\"mail@mail.ch\" subject=\"ip change\" body=\"ip-sfp1-pppoe
\n set ipadd \$thisip;\r\
\n}"
add name=sfp2-wan-ip-send owner=m4bwema policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":global i
\n:local thisip [/ip address get [find where interface=sfp2] address];\r\
\n\r\
\n:if (\$ipadd != \$thisip) do={\r\
\n /tool e-mail send to=\"mail@mail.ch\" subject=\"ip change\" body=\"ip-sfp2
\n set ipadd \$thisip;\r\
\n}"

Re: WAN IP email sending script

Posted: Wed Jun 28, 2017 5:27 am
by fengyuclub