返回列表 發帖
本帖最後由 角色 於 2013-9-8 21:32 編輯

#3帖的code,没有问题
  1. [admin@MikroTik] > /import file-name=dyndns-3.rsc
  2. Opening script file dyndns-3.rsc

  3.   status: finished

  4.   status: finished

  5. Dyndns Update Result: good 58.153.xxx.yyy
  6. Script file loaded and executed successfully
  7. [admin@MikroTik] >
複製代碼

TOP

本帖最後由 角色 於 2013-9-8 21:40 編輯

Another Script Link provided by member "bky16"
  1. ############
  2. # Set needed variables
  3. ############
  4. # Your DynDNS account user-name, password & host-name.
  5. :local username "yourusername"
  6. :local password "yourpassword"
  7. :local hostname "yourhostname"

  8. # Which interface are we checking if DHCP has changed? [interfaces | name column in winbox]
  9. :local DHCPInterface "yourinterface"
  10. ############
  11. # This is the name of the file where the last recorded IP will be stored, as well as the file name of the DynDNS response.
  12. # Make sure if another script is using files, that these names don't conflict.
  13. # You probably also want to be sure they aren't the same as any other files on the disk - because you'll be clobbering those files.
  14. # Finally, while I'm not aware of any "reserved" file names on the disk, it would be wise to avoid something that might conflict.
  15. # Prefixing them with something to associate them with this script would probably be a good thing.
  16. # You can point these files at your SD-disk too, if you have an SD card installed and ready on your RB. Just prefix the path appropriately:
  17. # something like this [:local vLastIPFileName "micro-sd/dyndns-lastip.txt"] (don't put a leading slash)
  18. # A user reported a bug if you use the RB flash and prefix the path with a [/]
  19. # So for RB based flash, it's probably safest to use just something like [:local vLastIPFileName "dyndns-lastip.txt"] and not [:local vLastIPFileName "/dyndns-lastip.txt"]
  20. # You ***MUST*** use a .txt extension. Just an oddity of ROS. Move along now.
  21. # Code ForDD
  22. :local vLastIPFileName "dyndns-lastip.txt"
  23. :local vDynDNSResponseFile "dyndns-resp.txt"
  24. # /dyndns.txt

  25. ############
  26. # END Set needed variables
  27. ############

  28. :local vlen;
  29. :local vRawIP;
  30. :local vJustIP;
  31. :local currentIP
  32. :local previousIP
  33. :local vlocalurl
  34. :local vIPChanged false
  35. :local dyndnsresult
  36. :local result

  37. # Check for file existance, if not create it
  38. # We need to do this before we try to read or write to files...
  39. :local check [/file find name=$vLastIPFileName]
  40. :if ( $check = "" ) do= {
  41.    /file print file=$vLastIPFileName
  42.    :delay 2
  43.    /file set [/file find name=$vLastIPFileName] contents=""
  44. }

  45. # Get the last saved IP from the file.
  46. :set previousIP [/file get $vLastIPFileName contents]
  47. #:put $previousIP


  48. # print some debug info
  49. :log info ("UpdateDynDNS: username = $username")
  50. :log info ("UpdateDynDNS: password = $password")
  51. :log info ("UpdateDynDNS: hostname = $hostname")
  52. :log info ("UpdateDynDNS: previousIP = $previousIP")
  53. :log info ("UpdateDynDNS: DHCPInterface = $DHCPInterface")


  54. # This code gets the current IP from the interface.
  55. # The interface we're checking should be set above.
  56. # get the raw IP from the interface, which includes a mask.
  57. :set vRawIP [:tostr [/ip address get [find interface=$DHCPInterface] address]]

  58. #Strip the netmask off the vRawIP address.
  59. :for i from=( [:len $vRawIP] - 1) to=0 do={
  60.         :if ( [:pick $vRawIP $i] = "/") do={
  61.                 :set vJustIP [:pick $vRawIP 0 $i]
  62.         }
  63. }
  64. :set currentIP $vJustIP

  65. # Determine if dyndns update is needed
  66. # more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html
  67. # Update if the currentIP isn't equal to previousIP.
  68. :if (($currentIP != $previousIP)) do={
  69.         :log info "CurrentIP: $currentIP - PreviousIP: $previousIP"
  70.         :set vlocalurl ("http://" . "$username" . ":" . "$password" . "@" . "members.dyndns.org" . "/nic/update?hostname=" . "$hostname" . "&myip=" . "$currentIP")   
  71.         /tool fetch mode=http url=$vlocalurl dst-path=$vDynDNSResponseFile
  72.         :set result [/file get $vDynDNSResponseFile contents]
  73.         :set vIPChanged true
  74. } else={
  75.    :log info ("UpdateDynDNS: No dyndns update needed")
  76. }

  77. # Get the result status code and pull it out for use.
  78. # IF IPChanged = true
  79. #        Get result code
  80. #                Check DynDNS result
  81. #                if good or nochg, then
  82. #                        :set previousIP $currentIP
  83. #                        /file set [/file find name=$vLastIPFileName] contents="$currentIP"
  84. #                        also post the result to the log file        
  85. #                else badauth or !donator or notfqdn, nohost, abuse, dnserr, 911
  86. #                        post to log file
  87. #                        Don't update previousIP or vLastIPFileName file
  88. :if ($vIPChanged=true) do={
  89.         :set result [/file get $vDynDNSResponseFile contents]
  90.         :local endLoc [:find $result " " -1]
  91.         :set dyndnsresult [:pick $result -1 ($endLoc)]
  92.         :put $dyndnsresult
  93.                 :if (($dyndnsresult = "good") || ($dyndnsresult = "nochg") ) do={
  94.                         :set previousIP $currentIP
  95.                         :log info ("UpdateDynDNS: Dyndns update needed")
  96.                         :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
  97.                         /file set [/file find name=$vLastIPFileName] contents="$currentIP"
  98.                         } \
  99.                 else={
  100.                         :log info ("UpdateDynDNS: Dyndns update needed")
  101.                         :log info ("DynDNS Update FAILED")
  102.                         :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
  103.                 }
  104. }
複製代碼
  1. New Terminal> /system scheduler add name=dyndns interval=00:01 on-event="/system script run dyndns\r\n"
複製代碼
Result 也 Okay
  1. [admin@MikroTik] > /import dyndns-bk.rsc
  2. Opening script file dyndns-bk.rsc

  3.   status: finished

  4. good
  5. Script file loaded and executed successfully
  6. [admin@MikroTik] >
複製代碼

TOP

现在bky16的script,一关电源,过了一晚,再试就没有把DNS更改。

那么估计还要修改一下。

TOP

现在正在测试bubblestar兄的script,看看关机后,再开是否可以把ip upgrade到最新的IP。

TOP

我也发现这个问题,问题是整个script都是看local file,而不是check DNS Server!所以等我有空的时候去学怎样去修改那段script,看看是否做到script去check DNS Server。

TOP

不知道其他members是否用的Script能关机后再能update DNS server呢?

TOP

效果怎样?你在大陆?

TOP

DynDNS一样,主要主hostname xxx.dyndns.org当然被blocked,但是用dyndns的sub-domian就没有问题。由于要收费,所以已经全部停用了。

TOP

那么奇怪?时能PM我的你的hostname,然后我从香港check一下看看?

TOP

DNS用香港的Servers,就是你是香港的ISP给你的DNS server。

TOP

因为是内部IP,不能在外面进入系统,所以要求更换Public IP。
我估计一般是给Private IP,如果有投诉才跟Public IP,估计电信估算很多人只是上网,而不需要public IP,所以给你private IP就算了。

所以你一定要投诉外面不可以登入!

TOP

返回列表