Community discussions

MikroTik App
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

One last little help please

Tue Apr 12, 2022 3:50 am

I have the following scripts:
:global interfaceIP "ETHERT 1"
:global filenameIP "historial de IPs.txt"

:global arrMonths {jan="ENE";feb="FEB";mar="MAR";apr="ABR";may="MAY";jun="JUN";jul="JUL";aug="AGO";sep="SEP";oct="OCT";nov="NOV";dec="DIC"}
{
:local ndate [/system clock get date]; :local ntime [/system clock get time]
:global now "HORA:$ntime   FECHA: $[:pick $ndate 4 6]-$($arrMonths->[:pick $ndate 0 3])-$[:pick $ndate 7 11]"
}
/file
:if ([:len [find where name="flash" and type="disk"]] = 1) do={:set filenameIP "flash/$filenameIP"}
:if ([:len [find where name=$filenameIP]] = 0) do={print file="$filenameIP"; :delay 5s; set $filenameIP contents=""}

:global currentIP
:if ([:len $currentIP] = 0) do={:set currentIP 0.0.0.0/0}
:local newIP [/ip address get [find interface="$interfaceIP"] address]
:set newIP [:pick $newIP 0 [:find $newIP "/" -1]]
:if ($newIP != $currentIP) do={
    /file
    :delay 5s
    :local filecontent [get $filenameIP contents]
    :local newfilecontent "NUEVA IP:$newIP\t$now\r\n$filecontent"
    set $filenameIP contents=$newfilecontent
    :set currentIP $newIP;
}

and this one that sends a new IP address to my email
:global currentIP;
:local newIP [/ip address get [find interface="ETHERT 1"] address];
:if ($newIP != $currentIP) do={
    :local newIP [/ip address get [find interface="ETHERT 1"] address];
/tool e-mail send to="therewasanemailaddress" subject=([/system identity 
get name]) body=" Esta es su nueva  direccion IP:  $newIP" start-tls=yes;
    :set currentIP $newIP;
}

When I activate both scripts, the second script that sends the new ip address to my email goes crazy and sends the ip address every 10 seconds, as I have it programmed. Thanks for your help.



EL DONCITO.
 
Rugx
Member Candidate
Member Candidate
Posts: 123
Joined: Thu Jan 02, 2020 1:44 pm

Re: One last little help please

Tue Apr 12, 2022 10:38 am

In the second script you are not removing the subnet from $newIP when comparing to $currentIP
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: One last little help please

Tue Apr 12, 2022 10:47 am

(Edit the previous post and remove the email...)

:global currentIP
:local newIP [/ip address get [find where interface="ETHERT 1"] address]
:set newIP [:pick $newIP 0 [:find $newIP "/" -1]]
:if ($newIP != $currentIP) do={
    /tool e-mail send to="***censored***" subject=[/system identity get name] start-tls=yes \
        body=" Esta es su nueva direccion IP:  $newIP"
    :set currentIP $newIP
}

Who is online

Users browsing this forum: freezerfcb, Snooops and 24 guests