Community discussions

MUM Europe 2020
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1274
Joined: Sun Sep 18, 2011 7:00 pm

script that send mail whwm Ip cahnge

Wed Nov 14, 2012 2:14 pm

Hello
I want to write a script that will run every 1 hours and check the IP I get and send me an E-mail if it's change.
this is what I wrote so fat
my problem is how to save the old ip \where to put him

:global newip [/ip address get [find interface=ppp-out1] address];
:log warning "New IP is-$newip";

:if ($oldip !=$newip) do={:log warning "IP change to-$newip";
/system script run mail;
:global oldip=$newip; } else={:log warning "IP didn't change";:global oldip=$newip; };

:log warning "******script finish******";


thanks ,
 
User avatar
NAB
Trainer
Trainer
Posts: 503
Joined: Tue Feb 10, 2009 4:08 pm
Location: UK
Contact:

Re: script that send mail whwm Ip cahnge

Wed Nov 14, 2012 6:45 pm

my problem is how to save the old ip \where to put him
Easiest place is in a comment field. In my experience, the best place is on the interface the DHCP server is running on (/interface etherX set comment="1.2.3.4") - that way it survives reboots and power cuts.
Nicholas Barnes BSc(hons)
Certified Mikrotik Consultant
Certified Mikrotik Trainer

Vitell - Asterisk, Linux and network consultants
Unofficial IRC channel: #routerboard on irc.z.je
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 558
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: script that send mail whwm Ip cahnge

Wed Nov 14, 2012 7:57 pm

try this


{
:global oldip;
:local newip [/ip address get [find interface=ppp-out1] address];
:log warning "New IP is-$newip";
:if ($oldip !=$newip) do={:log warning "IP change to-$newip";
/system script run mail; set oldip $newip} else={:log warning "IP didn't change"; };
:log warning "******script finish******";
}
nothing
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1274
Joined: Sun Sep 18, 2011 7:00 pm

Re: script that send mail whwm Ip cahnge

Thu Nov 15, 2012 10:42 am

this is good option
I did something else - I wrote the value into a file and then read\write to him.
but I'll try it also
Thanks !

1 more thing -
maybe you know how I can cancel the subnet of the ip

I get 91.152.24.87/32
I want to get only the 91.152.24.87
that way I can send the ip as a link

?

thanks ,
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 558
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: script that send mail whwm Ip cahnge

Fri Nov 16, 2012 3:32 am

like this
{
:local ip [/ip address get [/ip address find interface="wan"] address]
:local currentIP [:pick $ip 0 [:find $ip "/"]]
put $currentIP
}
nothing
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1274
Joined: Sun Sep 18, 2011 7:00 pm

Re: script that send mail whwm Ip cahnge

Sun Nov 18, 2012 10:48 am

Thank you!

1 more question -
how can I see the IP as a link? so the person will press it and go directly to the IP
in the E-mail I see this as a text - and not as a link
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 558
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: script that send mail whwm Ip cahnge

Mon Nov 19, 2012 3:18 am

{
:local ip [/ip address get [/ip address find interface="wan"] address]
:local currentIP [:pick $ip 0 [:find $ip "/"]]
put "http://$currentIP"
}
nothing
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1274
Joined: Sun Sep 18, 2011 7:00 pm

Re: script that send mail whwm Ip cahnge

Mon Nov 19, 2012 9:14 am

Thanks !

(again)

Who is online

Users browsing this forum: No registered users and 14 guests