Update Dynamic IP Public Di DynDNS Part 02

In Mikrotik 576 views

Aku sudah pernah menulis artikel mengenai update dynamic IP di DynDNS melalui Mikrotik Desember 2012 lalu, tapi sekarang script yang terdapat di artikel Akses Mikrotik Dengan DynDNS tidak bisa digunakan di Mikrotik versi 5.24.

Nah, diartikel yang sekarang ini ada beberapa perubahan sehingga script tersebut bisa digunakan dan kompatibel dengan Mikrotik versi 5.24. Bug pada script yang terdahulu yaitu pada perubahan / update label Current_IP di address list, pada log script sudah menunjukkan perubahan IP tapi tidak ada perubahan pada address list sehingga hostname dyndns tidak dapat diakses dari luar jaringan.

Pada script yang baru ini update dynamic ip tidak hanya terbatas pada DynDNS saja tapi juga dapat digunakan pada service selain DynDNS seperti, NoIP dan ChangeIP. Selain itu ada beberapa opsi yang harus disesuaikan agar script ini dapat berjalan maksimal.

Ok, langsung saja berikut script update dynamic IP tersebut :

#************************************************************************************************
# Parameters
#************************************************************************************************
:local username "<your username>"
:local password "<your password>"
:local hostname "<subdomain.yourprovider.net>"

#availabe options: "http" or "iface"
# - http: will query an external server and discover you public ip (userful for NATted connections)
# - iface: will use the ip address assigned to the $iface interface (see below)

:local discoverBy "iface"

# interface used to get ip address from (only if discoverBy = iface)

:local iface "public-dsl"

# current available services: "dyndns", "noip" and "changeip"
:local service "changeip"

# number of days to force an update if your IP did not change (helps keeping your account active)
:local forceUpdate 15

#************************************************************************************************
# do not change below this unless you know what you are doing
#************************************************************************************************

:local force
:global lastUpdate
:local currentIP

:if ($discoverBy="http") do={ 
   /tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
   :local result [/file get dyndns.checkip.html contents]
   :local resultLen [:len $result]
   :local startLoc [:find $result ": " -1]
   :set startLoc ($startLoc + 2)
   :local endLoc [:find $result "</body>" -1]
   :set currentIP [:pick $result $startLoc $endLoc]
} else={
   :set currentIP [ /ip address get [find interface=$iface disabled=no] address ]
   :for i from=( [:len $currentIP] - 1) to=0 do={
      :if ( [:pick $currentIP $i] = "/") do={ :set currentIP [:pick $currentIP 0 $i] } 
   }
}

#get IP from DynDNS for our hostname
:local resolvedIP [:resolve $hostname]

# get current date in format mm/DD/YYYY
:local date [ /system clock get date ]

# convert to YYYYMMDD
:local months ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
:local month [ :pick $date 0 3 ]; :local day [ :pick $date 4 6 ]; :local year [ :pick $date 7 11 ];
:local mm ([ :find $months $month -1 ] + 1);
:if ($mm < 10) do={ :set month ("0" . $mm); } else={ :set month $mm; }
:set date ($year . $month . $day);

:if ([ :typeof $lastUpdate ]=[:nothing] || (($date-$lastUpdate) >= $forceUpdate  && $forceUpdate > 0)) do={ 
   :set force true 
}

:put ("Current IP: $currentIP ($discoverBy), Last update: $lastUpdate")

# Determine if dyndns update is needed
:if (($currentIP != $resolvedIP) || ($force = true)) do={
    
    :if ($service = "dyndns") do={
       /tool fetch user=$username password=$password mode=http address="members.dyndns.org" 
            src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/output.txt"
    }
    :if ($service = "noip") do={
       /tool fetch user=$username password=$password mode=http address="dynupdate.no-ip.com" 
            src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/output.txt"
    }
    :if ($service = "changeip") do={
       /tool fetch user=$username password=$password mode=http address="nic.changeip.com" 
            src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/output.txt"
    }
   
    :local result [/file get output.txt contents]
    :log info ("dynamic-dns-updater: Service = $service, Hostname = $hostname")
    :log info ("dynamic-dns-updater: CurrentIP = $currentIP, Resolved IP = $resolvedIP")
    :log info ("dynamic-dns-updater: Update result: ".$result)
    /ip dns cache flush
    :set lastUpdate $date
}

 

source : forum.mikrotik.com

Setelah dibuat tinggal memasukkan script tersebut ke scheduler untuk dijalankan pada rentang waktu yang diinginkan.

Selamat mencoba dan bereksperimen ….. salam

Related Search

Tags: #IP #Mikrotik Desember #service #YYYYMMDD


MikroTik Deteksi IP Lokal / Public Indihome
MikroTik Deteksi IP Lokal / Public Indihome
Kecepatan koneksi dan harga Indihome menjadi daya
Mikrotik Duckdns.org Update (New Script)
Mikrotik Duckdns.org Update (New Script)
Entah kenapa script untuk update Dynamic IP
Setup Storage Path The Dude di RB750G r3
Setup Storage Path The Dude di RB750G r3
The Dude merupakan tool yang cukup penting
Cara Membuat Certificates di MikroTik
Cara Membuat Certificates di MikroTik
Certificates yang dibuat pada Mikrotik ini dapat

Top