Community discussions

MikroTik App
 
User avatar
fengyuclub
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 61
Joined: Mon Dec 09, 2013 8:50 am

how to mail me if isp ip change (pppoe)?

Thu Aug 11, 2016 1:30 pm

Hi guys , I need a script code ,when my isp(pppoe) ip address changed ,send this changed ip to mymail,if ip isn't changed no send. How to do???
 
User avatar
fengyuclub
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 61
Joined: Mon Dec 09, 2013 8:50 am

Re: how to mail me if isp ip change (pppoe)?

Fri Aug 12, 2016 6:07 am

i am a chinese user,my english is poor,please help me . thanks.
 
squeezypiano
newbie
Posts: 42
Joined: Tue Oct 09, 2012 10:05 pm
Location: Scotland

Re: how to mail me if isp ip change (pppoe)?

Sat Aug 13, 2016 3:35 pm

Hi,

I run a scheduled script, below, at regular intervals. Make sure your email settings on the router are working first and change the interface name as required. The script store the address in a firewall address-list so it can compare it if it changes. I use the same address-list for my hairpin NAT so they always work.
:local oldip [/ip firewall address-list get [find list="externalip"] address];
:local newip [/ip address get [find interface="ether1"] address];
:local newip [:pick $newip 0 [:find $newip "/"]];

:if ($newip != $oldip) do={
    :put "ip address $old changed to $newip";
    /ip firewall address-list set [find list="externalip"] address=$newip

    :put "Sending e-mail.";
    /tool e-mail send \
        to="someone@somewhere.com" \
        subject=("$[/system identity get name] Ether1 address change") \
        body=("Your Ether1 address has just been changed:\n\nOld: " . $oldip . "\nNew: " . $newip);
}
 
User avatar
fengyuclub
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 61
Joined: Mon Dec 09, 2013 8:50 am

Re: how to mail me if isp ip change (pppoe)?

Mon Aug 15, 2016 12:42 pm

Hi,

I run a scheduled script, below, at regular intervals. Make sure your email settings on the router are working first and change the interface name as required. The script store the address in a firewall address-list so it can compare it if it changes. I use the same address-list for my hairpin NAT so they always work.
:local oldip [/ip firewall address-list get [find list="externalip"] address];
:local newip [/ip address get [find interface="ether1"] address];
:local newip [:pick $newip 0 [:find $newip "/"]];

:if ($newip != $oldip) do={
    :put "ip address $old changed to $newip";
    /ip firewall address-list set [find list="externalip"] address=$newip

    :put "Sending e-mail.";
    /tool e-mail send \
        to="someone@somewhere.com" \
        subject=("$[/system identity get name] Ether1 address change") \
        body=("Your Ether1 address has just been changed:\n\nOld: " . $oldip . "\nNew: " . $newip);
}
Nice! your script is work,thankyou very much

Who is online

Users browsing this forum: No registered users and 41 guests