Community discussions

MikroTik App
 
Eliminateur
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 96
Joined: Thu Jun 28, 2007 7:38 am

WAN IP email sending script

Thu Jul 07, 2011 10:03 pm

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?
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: WAN IP email sending script

Thu Jul 07, 2011 11:56 pm

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.
 
Eliminateur
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 96
Joined: Thu Jun 28, 2007 7:38 am

Re: WAN IP email sending script

Fri Jul 08, 2011 8:20 pm

thanks, using your script(much simpler as well) worked like a charm!
 
Nanflexal
Member Candidate
Member Candidate
Posts: 127
Joined: Wed Sep 16, 2009 7:34 am

Re: WAN IP email sending script

Mon Jul 08, 2013 4:04 pm

can we modify this to send email is one WAN interface is down.

thanks
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: WAN IP email sending script

Tue Jul 09, 2013 2:49 am

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.
 
User avatar
Reborns
just joined
Posts: 5
Joined: Wed Jun 12, 2013 4:35 pm

Re: WAN IP email sending script

Sat Aug 03, 2013 8:19 am

SurferTim

Can you re-check script please ??? after upgrading to ROSv6 script doesn't work anymore ...
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: WAN IP email sending script

Sat Aug 03, 2013 1:28 pm

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.
 
ALX1S
newbie
Posts: 44
Joined: Mon Apr 27, 2015 5:28 pm
Location: Buenos Aires, Argentina

Re: WAN IP email sending script

Sat Sep 12, 2015 9:09 pm

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)
 
Ingemars
just joined
Posts: 1
Joined: Mon Feb 08, 2016 7:42 am

Re: WAN IP email sending script

Sun Mar 13, 2016 11:06 pm

Running fine on v 6.35rc16 on RB951G-2HnD.
Thank you for posting this useful script.
 
markuswenger
just joined
Posts: 4
Joined: Tue Jun 13, 2017 9:06 am

Re: WAN IP email sending script

Tue Jun 13, 2017 9:31 pm

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}"
 
User avatar
fengyuclub
Member Candidate
Member Candidate
Posts: 109
Joined: Mon Dec 09, 2013 8:50 am

Re: WAN IP email sending script

Wed Jun 28, 2017 5:27 am

Who is online

Users browsing this forum: No registered users and 9 guests