Network

تحديث عنوان IP لخدمة Dynu DDNS — 6

يقارن عنوان IP لواجهة الإنترنت مع عنوان IP الخاص باسم المضيف في Dynu ويحدّث Dynu عند الاختلاف. شغّله من الـ Scheduler (مثلاً كل 5 دقائق).

إصدار ⁨MikroTik⁩

RouterOS 6

# EN: Dynu account username | AR: اسم مستخدم حساب Dynu
:local ddnsuser "change here";
# EN: Dynu account password (or IP Update Password) | AR: كلمة مرور Dynu (أو IP Update Password)
:local ddnspass "change here";
# EN: Name of the WAN interface that holds your public IP | AR: اسم واجهة الإنترنت التي تحمل الـ IP العام
:local theinterface "change here";
# EN: Your Dynu hostname, e.g. example.ddnsfree.com | AR: اسم المضيف في Dynu
:local ddnshost "change here";

# EN: Safety check | AR: حماية من عدم تعديل المتغيرات
:if ($ddnsuser = "change here" || $ddnspass = "change here" || $theinterface = "change here" || $ddnshost = "change here") do={ :error "Edit the variables first" }

# EN: IP currently registered in DNS (empty if it cannot be resolved) | AR: الـ IP المسجل حالياً في DNS
:local ipddns "";
:do { :set ipddns [:resolve $ddnshost] } on-error={ :log warning "dynu: cannot resolve host" }

# EN: Current IP of the WAN interface | AR: الـ IP الحالي لواجهة الإنترنت
:local ipfresh "";
:do { :set ipfresh [/ip address get [/ip address find interface=$theinterface] address] } on-error={ :log warning "dynu: no ip address on interface" }
:if ($ipfresh = "") do={ :error "dynu: no ip address on interface" }

# EN: Remove the /mask part (1.2.3.4/24 -> 1.2.3.4) | AR: حذف جزء القناع (/24)
:set ipfresh [:pick $ipfresh 0 [:find $ipfresh "/"]];

:if ($ipddns != $ipfresh) do={
    :log info ("dynu: DNS IP = $ipddns, WAN IP = $ipfresh, updating...");
    :local path ("/nic/update?hostname=" . $ddnshost . "&myip=" . $ipfresh);
    # EN: Send the update request to Dynu | AR: إرسال طلب التحديث إلى Dynu
    /tool fetch address=api.dynu.com src-path=$path mode=http user=$ddnsuser password=$ddnspass dst-path=("Dynu." . $ddnshost);
    :delay 1s;
    # EN: Delete the downloaded response file | AR: حذف ملف الرد الذي تم تحميله
    /file remove [/file find name=("Dynu." . $ddnshost)];
    :log info ("dynu: IP updated to $ipfresh");
} else={
    :log info "dynu: no changes needed";
}