大致上內容沒有變更多少,只是多了一個減少上傳的腳本,讓腳本判斷IP是否有變動,有變動才會上傳新的IP位置給Freedns,如何取得更新IP的Url,這方面可以參考上一篇舊的更新方式。
首先我們先建立腳本
路徑:System→Script
按「+」新增一個腳本設置就這樣
程式碼的部分貼進去
#定義參數
:global FerrDnsIP value=[/ip address get [find where interface=pppoe-out1] value-name=address];
:global FerrDnsIP value=[:pick $FerrDnsIP -1 [:find $FerrDnsIP "/" -1] ];
#ips.txt判定
:if ([:len [/file find where name=ips.txt]] < 1 ) do={
/file print file=ips.txt where name=ips.txt;
/delay delay-time=2;
/file set ips.txt contents="0.0.0.0";
};
#判定更新
:global FreeDnsOldIP value=[/file get [find where name=ips.txt ] value-name=contents];
:if ($FreeDnsOldIP != $FerrDnsIP) do={
#系統紀錄
:log info message=("Try to Update FreeDNS with FerrDnsIP ".$FerrDnsIP." - FreeDnsOldIP are ".$FreeDnsOldIP);
/tool fetch url="這裡輸入自己的Url" mode=https;
:global FreeDnsOldIP value=$FerrDnsIP;
/file set ips.txt contents=$FerrDnsIP;
};
貼進去後可以點及Run Script 跑一次,成功的話可以看到這兩個檔案出現File list裡面,還有兩個參數會在Environment裡面。
接下來要設定間隔幾分鐘運作一次
路徑:System→Scheduler
按「+」新增
程式碼的部分貼進去
/system script run freedns這樣就完成了,跟舊的一樣我是設定15分鐘檢查一次,檢查的時間跟腳本的名稱,可以依照自己的需求變更。




沒有留言:
張貼留言