This page has been translated from Italian
October
07

Using DynDNS with RouterOS

| 2 commenti | TrackBack | | | 2 comments | TrackBack |
una stelladue stelletre stellequattro stellecinque stelle (Rate this article!)
Loading ... Loading ...
Bookmark and Share

The script below allows those who have a RouterBOARD Mikrotik or a system loaded with RouterOS to update the addresses of your account on DynDns.org .

The script, to be configured, need to update the host name, username and password for your DynDNS account, and the interface on which the address is dynamically assigned by the provider.

The following script, when run, it updates its configuration

:global ddnsuser "YOUR_USERNAME"
:global ddnspass "YOUR_PASSWORD"
:global ddnshost "YOUR.DOMAIN.EXT"
:global ddnsinterface "THE_INTERFACE"

:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface] address ]
:global ddnslastip
:if ([:len [/interface find name=$ddnsinterface]] = 0 ) do={ :log info "DDNS: No interface named $ddnsinterface, please check configuration." }
:if ([ :typeof $ddnslastip ] = "nothing" ) do={ :global ddnslastip 0.0.0.0/0 }
:if ([ :typeof $ddnsip ] = "nothing" ) do={
:log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={
  :if ($ddnsip != $ddnslastip) do={
    :log info "DDNS: Sending UPDATE!"
    :local ddnsip1 [:pick $ddnsip 0 [:find $ddnsip "/"] ];
    :local str "/nic/update?hostname=$ddnshost&myip=$ddnsip1";
    /tool fetch address=members.dyndns.org src-path=$str mode=http user=$ddnsuser password=$ddnspass dst-path=("/DynDNS.".$ddnshost)
    :delay 1
    :local str [/file find name="DynDNS.$ddnshost"];
    /file remove $str
    :global ddnslastip $ddnsip
  } else={
    :log info "DDNS: No changes necessary."
  }
}

Questo script può, ovviamente essere eseguito automaticamente, ogni ora o anche meno, usando lo scheduler.

Riporto qui sotto, per comodità, i comandi da incollare in una finestra del terminale del winbox, che aggiungono lo script sopra e uno scheduler che esegue lo script ogni 10 minuti

/system script
add name="DynDNS update" policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source="\
:global ddnsuser \"YOUR_USERNAME\"\r\
\n:global ddnspass \"YOUR_PASSWORD\"\r\
\n:global ddnshost \"YOUR.DOMAIN.EXT\"\r\
\n:global ddnsinterface \"THE_INTERFACE\"\r\
\n:global ddnsip [ /ip address get [/ip address find interface=\$ddnsinter\
face] address ]\r\
\n:global ddnslastip\r\
\n:if ([:len [/interface find name=\$ddnsinterface]] = 0 ) do={ :log info \
\"DDNS: No interface named \$ddnsinterface, please check configuration.\" \
}\r\
\n:if ([ :typeof \$ddnslastip ] = \"nothing\" ) do={ :global ddnslastip 0.\
0.0.0/0 }\r\
\n:if ([ :typeof \$ddnsip ] = \"nothing\" ) do={\r\
\n:log info (\"DDNS: No ip address present on \" . \$ddnsinterface . \", p\
lease check.\")\r\
\n} else={\r\
\n  :if (\$ddnsip != \$ddnslastip) do={\r\
\n    :log info \"DDNS: Sending UPDATE!\"\r\
\n\t:local ddnsip1 [:pick \$ddnsip 0 [:find \$ddnsip \"/\"] ];\r\
\n\t:local str \"/nic/update\?hostname=\$ddnshost&myip=\$ddnsip1\";\r\
\n    /tool fetch address=members.dyndns.org src-path=\$str mode=http user\
=\$ddnsuser password=\$ddnspass dst-path=(\"/DynDNS.\".\$ddnshost)\r\
\n    :delay 1\r\
\n    :local str [/file find name=\"DynDNS.\$ddnshost\"];\r\
\n    /file remove \$str\r\
\n    :global ddnslastip \$ddnsip\r\
\n  } else={ \r\
\n    :log info \"DDNS: No changes necessary.\"\r\
\n  }\r\
\n}"

/system scheduler
add comment="" disabled=no interval=1h name="Schedule DynDNS Update" \
on-event="/system script run \"DynDNS update\"" policy=\
reboot,read,write,policy,test,password,sniff,sensitive start-time=startup
Questo articolo è stato visto 334 volta

2 Responses to “Usare DynDns con RouterOs”

Lascia un commento

 

Categorie

Articoli Più Visti

Questo articolo è stato visto 334 volta

2 Responses to “Usare DynDns con RouterOs”

Lascia un commento

 

Categorie