Code: Select all
:global interfaceIP "ETHERT 1"
:global filenameIP "iphistory.txt"
:global arrMonths {jan="01";feb="02";mar="03";apr="04";may="05";jun="06";jul="07";aug="08";sep="09";oct="10";nov="11";dec="12"}
{
:local data [/system clock get date]
:local itime [/system clock get time]
:local hours [:pick $itime 0 2]
:local minsec [:pick $itime 2 8]
:local mhours [:tonum $hours]
:local msymbl "AM"
:if ($mhours > 11) do={:set msymbl "PM"}
:set mhours ($mhours % 12)
:if ($mhours = 0) do={:set mhours 12}
:if ($mhours < 10) do={:set mhours "0$mhours"}
:local mtime "$mhours$minsec $msymbl"
:global now "time:$mtime date: $[:pick $data 4 6]-$($arrMonths->[:pick $data 0 3])-$[:pick $data 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 "new IP:$newIP\t$now\r\n$filecontent"
set $filenameIP contents=$newfilecontent
:set currentIP $newIP;
}
here we have an example:
Code: Select all
new IP:186.95.13.112 time:18:57:20 PM date: 06-04-2022
new IP:186.95.45.220 time:08:54:30 AM date: 15-04-2022
new IP:190.78.186.59 time:07:34:20 PM date: 14-04-2022
new IP:186.95.84.150 time:05:49:30 PM date: 14-04-2022
new IP:186.95.45.220 time:05:35:51 PM date: 14-04-2022
new IP:190.72.12.81 time:05:34:23 PM date: 14-04-2022
EL DONCITO: