سكربت التحديث الديناميكي DNS لنظام dynDNS في سيرفرات الميكروتك

اخر تحديث في مايو 27, 2023 بواسطة حمدي بانجار

سكربت التحديث الديناميكي DNS لنظام dynDNS في سيرفرات الميكروتك

من أجل دعم dyndns أخذت بعض الأجزاء من سكربت changeip لجعلها تعمل .

1) إضافة سكربت يسمى dynDNS:

ملاحظة :

قد تكون المقالة محمية ضد النقل وبالتالي لنسخ الاكواد ان وجدت انقر على علامة + بأعلى يمين الكود والتي تظهر عند تمرير الماوس على الكود .

# Define User Variables
:global ddnsuser "DYNDNSUSER"
:global ddnspass "DYNDNSPASS"
:global ddnshost "DYNDNSHOST"

# Define Global Variables
:global ddnsip
:global ddnslastip
:if ([ :typeof $ddnslastip ] = nil ) do={ :global ddnslastip "0" }

:global ddnsinterface
:global ddnssystem ("mt-" . [/system package get system version] )

# Define Local Variables
:local int

# Loop thru interfaces and look for ones containing
# default gateways without routing-marks
:foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes ] do={
  :if ([:typeof [/ip route get $int routing-mark ]] != str ) do={
     :global ddnsinterface [/ip route get $int interface]
  }
}

# Grab the current IP address on that interface.
:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface ] address ]

# Did we get an IP address to compare?
:if ([ :typeof $ddnsip ] = nil ) do={
   :log info ("DynDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={
  :if ($ddnsip != $ddnslastip) do={
    :log info "DynDNS: Sending UPDATE!"
    :local str "/nic/update?hostname=$ddnshost&myip=$ddnsip&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
    :local str [/file find name="DynDNS.$ddnshost"];
    /file remove $str
    :global ddnslastip $ddnsip
  }
}

2) إضافة إدخال الجدولة scheduler للتشغيل كل دقيقة :

/system scheduler add name=dynDNS interval=00:01 on-event="/system script run dynDns\r\n"

يوجد هنا موضوع لمن لدية المزيد من الأسئلة على منتديات الدعم Mikrotik.

Getting it to work with 4.XX :

# Set needed variables
:local username "YourUsername"
:local password "YourPassword"
:local hostname "nohostset"
:global systemname [/system identity get name]

:if ($systemname  = "Site1" ) do= {
:set hostname "yourdomain1.dyndns.org"
}
:if ($systemname  = "Site2" ) do= {
:set hostname "yourdomain2.dyndns.org"
}
:if ($systemname  = "Site3" ) do= {
:set hostname "yourdomain3.dyndns.org"
}

:global dyndnsForce
:global previousIP

# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
:local result [/file get dyndns.checkip.html contents]

# parse the current IP result
:local resultLen [:len $result]
:local startLoc [:find $result ": " -1]
:set startLoc ($startLoc + 2)
:local endLoc [:find $result "</body>" -1]
:local currentIP [:pick $result $startLoc $endLoc]
:log info "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
#  but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
    :set dyndnsForce false
    :set previousIP $currentIP
    /tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
       src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"
    :local result [/file get dyndns.txt contents]
    :log info ("UpdateDynDNS: Dyndns update needed")
    :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
    :put ("Dyndns Update Result: ".$result)
} else={
    :log info ("UpdateDynDNS: No dyndns update needed")
}

إذا واجهت مشاكل في تشغيل هذه السكربتات ، فجرّب:

:local ddnsuser "your user name"
:local ddnspass "your password"
:local theinterface "device to renove IP"
:local ddnshost "yourhost.dyndns.org"
:local ipddns [:resolve $ddnshost];
:local 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...!"
   :local 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
    :local str [/file find name="DynDNS.$ddnshost"];
    /file remove $str
    :global ipddns $ipfresh
  :log info "DynDNS: IP updated to $ipfresh!"
    } else={
     :log info "DynDNS: dont need changes";
    }
}

نسخة أخرى من هذا السكربت يعمل في 5.x :

# Set needed variables
:local username "YOURUSER"
:local password "YOURPASWORD"
:local hostname "YOURHOSTNAME.dyndns.org"

:global dyndnsForce
:global previousIP 

# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
:delay 1
:local result [/file get dyndns.checkip.html contents]

# parse the current IP result
:local resultLen [:len $result]
:local startLoc [:find $result ": " -1]
:set startLoc ($startLoc + 2)
:local endLoc [:find $result "</body>" -1]
:local currentIP [:pick $result $startLoc $endLoc]
:log info "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html

:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
   :set dyndnsForce false
   :set previousIP $currentIP
   :log info "$currentIP or $previousIP"
   /tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
      src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no" \
      dst-path="/dyndns.txt"
   :delay 1
   :local result [/file get dyndns.txt contents]
   :log info ("UpdateDynDNS: Dyndns update needed")
   :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
   :put ("Dyndns Update Result: ".$result)
} else={
   :log info ("UpdateDynDNS: No dyndns update needed")
}

إصدار Debugged لـ RoS 6.x:

:global ddnsuser "theddnsusername"
:global ddnspass "theddnspassword"
:global theinterface "interfacename"
:global ddnshost blabla.dyndns.org
: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!"
    } else={
     :log info "DynDNS: dont need changes";
    }
}

Scheduler:

/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

أنتهى … اسكربت التحديث الديناميكي DNS لنظام dynDNS في سيرفرات الميكروتك

اسكربت التحديث الديناميكي DNS لنظام dynDNS في سيرفرات الميكروتك

ملاحظة :

قد تكون المقالة محمية ضد النقل وبالتالي لنسخ الاكواد ان وجدت انقر على علامة + بأعلى يمين الكود والتي تظهر عند تمرير الماوس على الكود .

الى هنا نكون وصلنا الى نهاية موضوعنا اليوم سكربت التحديث الديناميكي DNS لنظام dynDNS في سيرفرات الميكروتك

والذي نتمنى ان ينال رضاكم واعجابكم والى اللقاء في موضوع جديد شيق ورائع

وحتى ذلك الحين لاتنسو الاهتمام بصحتكم وحفظكم الله …

اذا اعجبك سكربتات التحديث الديناميكي DNS لنظام dynDNS في سيرفرات الميكروتك الموضوع لاتبخل علينا بمشاركتة على مواقع التواصل الاجتماعي ليستفيذ منه الغير,

كما نتمنى اشتراككم في قناة الموقع على اليوتيوب بالضغط هنا وكذلك الاشتراك في مجموعة الفيس بوك بالضغط هنا والتيليقرام بالضغط هنا

وكذلك التسجيل بالموقع لتتمكنو من تحميل بعض الملفات الخاصة بالأعضاء

كما يمكنكم رفع ملفاتكم مجانا على مركز ملفات حضرموت التقنية بالضغط هنا ولاتترددو في وضع أي استفسارات للرد عليكم .

دمتم بكل ود والسلام عليكم ورحمة الله وبركاتة  … حضرموت التقنية

حول حمدي بانجار

باحث ومهندس في مجالات شبكات ومقاهي الأنترنت - شغوف في عالم الانترنت والبرمجة للشبكات - في حضرموت التقنية شعارنا الدائم - أفعل الخير مهما أستصغرتة ! فأنك لاتدري اي عمل يدخلك الجنة ... فلا يفلح كاتم العلم ...طموحاتي ان يصبح الموقع مدرسة تعليمية للعلوم التقنية الجديدة ومساعدة الاخرين في حل مشكلاتهم ونرحب بمن يرغب الانظمام لنا يفيذ ويستفيذ ليكبر هذا الصرح التعليمي ويحقق الاستفاذة القصوى للغير ... أنظمامكم لأسرة الموقع وقناتها ومشاركتكم بالمواضيع الهادفه هو بحد ذاتة تشجيع لنا وللغير لاستمرارية هذا الصرح التعليمي

تحقق أيضا

Tools/Bandwidth Test ادوات اختبار الباندوث في سيرفر الميكروتك

Tools/Bandwidth Test ادوات اختبار الباندوث في سيرفر الميكروتك

اخر تحديث في مايو 27, 2023 بواسطة حمدي بانجار Tools/Bandwidth Test ادوات اختبار الباندوث في …