Sending your self an e-mail with DSL interface IP address

From MikroTik Wiki
Revision as of 09:21, 13 June 2008 by Tplecko (talk | contribs)
Jump to: navigation, search

The goal

The goal is to know yout DSL interface IP address at all time if you need to connect to your MT box for any reason. It is a simple script.

The script

Create a new script with the following source

:global ddnsip
:global ddnslastip
:if ([ :typeof $ddnslastip ] = nil ) do={ :global ddnslastip "0" }
#:log info "v-ddnslastip= $ddnslastip"

:global ddnsinterface
:global ddnssystem ("Version-" . [/system package get system version] )
#:log info "v-ddnssystem= $ddnssystem"

:local int

:foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes ] do={
  :if ([:typeof [/ip route get $int routing-mark ]] != str ) do={
     :global ddnsinterface [/ip route get $int interface]
#     :log info "v-ddnsinterface= $ddnsinterface"
  }
}


:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface ] address ]
#:log info "v-ddnsip= $ddnsip"
:if ([ :typeof $ddnsip ] = nil ) do={
   :log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={

  :if ($ddnsip != $ddnslastip) do={
    :global datum [/system clock get date]
    :global vrijeme [/system clock get time]
    /tool e-mail send from=from@email.here.com to=to@email.here.com subject="DSL IP $datum $vrijeme" body="DSL IP $ddnsip" server=mail.server.ip.address
    :log info "DDNS: Sending UPDATE!"
    :global ddnslastip "$ddnsip"
  } else={
#    :log info "DDNS: No update required."
  }
}

The schedule

Create a schedule that runs the script every ten or so minutes and save.

add comment="" disabled=no interval=10m name=schedule1 on-event="sys scr run 4" start-date=may/15/2008 start-time=09:00:00

Replace the script number with the correct number.

Since it is a simple script, you can schedule it to run every minute.