Selasa, 10 Juni 2014
Script API Mikrotik for Autoupdate Port Forwarding NAT by IP DDNS (revised)
Script untuk mikrotik Os6 dan Os5 menggunakan Provider dari DynDns.com
:global ddnsuser "username"
:global ddnspass "password"
:global theinterface "WAN"
:global ddnshost your-domain.dyndns.net
:global ipddns [:resolve $ddnshost];
:global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
:if ([ :typeof $ipfresh ] = nil ) do={
:log info ("DynDNS: No ip address on $theinterface .")
} else={
:for i from=( [:len $ipfresh] - 1) to=0 do={
:if ( [:pick $ipfresh $i] = "/") do={
:set ipfresh [:pick $ipfresh 0 $i];
}
}
:if ($ipddns != $ipfresh) do={
:log info ("DynDNS: IP-DynDNS = $ipddns")
:log info ("DynDNS: IP-Fresh = $ipfresh")
:log info "DynDNS: Update IP needed, Sending UPDATE...!"
:global str "/nic/update\?hostname=$ddnshost&myip=$ipfresh&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
/tool fetch address=members.dyndns.org src-path=$str mode=http user=$ddnsuser \
password=$ddnspass dst-path=("/DynDNS.".$ddnshost)
:delay 1
:global str [/file find name="DynDNS.$ddnshost"];
/file remove $str
:global ipddns $ipfresh
:log info "DynDNS: IP updated to $ipfresh!"
/ip firewall nat
# set ini maksudnya nomor di firewall nat yang akan di update dari angka 1 s/d terakhir , berhubung yang diupdate pada line ke 1,16.34,35
maka saya pasang (set) discriptnya
set 1 dst-address=$ipfresh
set 16 dst-address=$ipfresh
set 34 dst-address=$ipfresh
set 35 dst-address=$ipfresh
} else={
:log info "DynDNS: dont need changes";
/ip firewall nat
set 1 dst-address=$ipfresh
set 16 dst-address=$ipfresh
set 34 dst-address=$ipfresh
set 35 dst-address=$ipfresh
}
}
dan beri nama dyndns --kemudian jalankan scriptnya ( run script)
=======================================================
Schedule
/system scheduler
add interval=1m name=DynDns on-event=DynDns policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-time=startup
dan beri nama scheduleDyndns
Semoga bermanfaat..
Langganan:
Posting Komentar (Atom)
klo buat ChangeIp, mana yg harus di ganti gan?
BalasHapus