routeos_ddns

#定義 no.ip 相關設定,以下自行修改:
#============================================================
:local DDNSUser "ggggg"
:local DDNSPassword "gggg"
:local DDNSHost "gggggg"
:local DDNSInterface "pppoe-out1″
#============================================================

#以下程式如不了解,建議不要修改:
#——————————————————————————————
#定義 IP 變數
:local DDNSIP
:global DDNSLastIP

#定義變數預設值
:if ([ :typeof $DDNSLastIP ] = nil ) do={ $DDNSLastIP "0.0.0.0″ }

#取得網路介面 IP 位址
:set DDNSIP [ /ip address get [/ip address find interface=$DDNSInterface ] address ]
:set DDNSIP [ :pick $DDNSIP 0 [ :find $DDNSIP "/" ] ]

#判斷是否要更新 IP
:if ([ :typeof $DDNSIP ] = nil ) do={
:log error ("DDNS no.ip: 網路介面 " . $DDNSInterface . " 未取得 IP 位址")
} else={
:if ($DDNSIP != $DDNSLastIP) do={
# 更新 DDNS IP
:local url "/nic/update?hostname=$DDNSHost&myip=$DDNSIP"
/tool fetch address=dynupdate.no-ip.com src-path=("$url") mode=http user=$DDNSUser password=$DDNSPassword dst-path=("DDNS_no_ip_$DDNSInterface")
:delay 1

# 檔案內容
:local filestr [ /file get "DDNS_no_ip_$DDNSInterface" contents];

# 刪除檔案
:local filename [ /file find name="DDNS_no_ip_$DDNSInterface"];
/file remove $filename

# 變更是否成功
:if ( [ :find $filestr "good"] = "0″ || [ :find $filestr "nochg"] = "0″ ) do={
:log warning ("DDNS no.ip: 網路介面 " . $DDNSInterface . " 更新 IP 位址 " . $DDNSIP)
:set DDNSLastIP $DDNSIP
} else={
:log error ("DDNS no.ip: 網路介面 " . $DDNSInterface . " 更新 IP 位址失敗 " . $DDNSIP)
}
}
}
#——————————————————————————————

本篇發表於 未分類。將永久鍊結加入書籤。

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>