Advertisement
Guest User

ddns mikrotik script

a guest
Sep 1st, 2016
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. # No-IP automatic Dynamic DNS update
  2.  
  3. # Wolf_KTL v.3.0
  4.  
  5. wolf_ktl@mail.ru
  6.  
  7. #--------------- Change Values in this section to match your setup ------------------
  8.  
  9. # No-IP User account info
  10. :local noipuser "имя пользователя"
  11. :local noippass "пароль"
  12.  
  13. # Set the hostname or label of network to be updated.
  14. # Hostnames with spaces are unsupported. Replace the value in the quotations below with your host names.
  15. # To specify multiple hosts, separate them with commas.
  16. :local noiphost "имя.no-ip.org"
  17.  
  18. # Change to the name of interface that gets the dynamic IP address
  19. :local inetinterface "интерфейс"
  20.  
  21. #------------------------------------------------------------------------------------
  22. # No more changes need
  23. # Данная переменная должна быть уникальной для каждого подключения интернет
  24. :global previousIPFlex
  25.  
  26. :if ([/interface get $inetinterface value-name=running]) do={
  27. # Get the current IP on the interface
  28. :local currentIP [/ip address get [find interface="$inetinterface" disabled=no] address]
  29.  
  30. # Strip the net mask off the IP address
  31. :for i from=( [:len $currentIP] - 1) to=0 do={
  32. :if ( [:pick $currentIP $i] = "/") do={
  33. :set currentIP [:pick $currentIP 0 $i]
  34. }
  35. }
  36. :log info " ************* $noiphost *********************" ;
  37. :log info "polu4aem ip $noiphost na interface $inetinterface" ;
  38. :local tempip [:resolve $noiphost];
  39. :log info "sravnivaem ip $noiphost i ip interface $inetinterface";
  40.  
  41. # и так сравниваем текущий ip адрес провайдера с нашей переменной, если они не совпадают меняем ip на no-ip.org
  42. :if ($currentIP != $previousIPFlex) do={
  43.  
  44. :log info "No-IP: Current IP $currentIP is not equal to previous IP, update needed"
  45. :set previousIPFlex $currentIP
  46.  
  47. # The update URL. Note the "\3F" is hex for question mark (?). Required since ? is a special character in commands.
  48. :local url "http://dynupdate.no-ip.com/nic/update\3Fmyip=$currentIP"
  49. :local noiphostarray
  50. :set noiphostarray [:toarray $noiphost]
  51. :foreach host in=$noiphostarray do={
  52. :log info "No-IP: Sending update for $host"
  53. /tool fetch url=($url . "&hostname=$host") user=$noipuser password=$noippass mode=http dst-path=("no-ip_ddns_update-" . $host . ".txt")
  54. :log info "No-IP: Host $host updated on No-IP with IP $currentIP"
  55. # Чистим кеш DNS (вопрос зачем?) если мы не почитим его то тогда команда resolve $noiphost будет бессмысленна . т.к в DNS кеше храниться не правильный IP
  56. /ip dns cache flush
  57.  
  58. }
  59. } else={
  60. # и так сравниваем текущий ip адрес провайдера с нашей переменной (полученной в результате команды resolve $noiphost ), если они не совпадают меняем ip на no-ip.org
  61. :if ($currentIP != $tempip) do={
  62. :log info "otvet ot No-IP: IP $noiphost raven tekushemu na interface $inetinterface, obnovlenie trenuetsya"
  63.  
  64. :log info "No-IP: Current IP $currentIP is not equal to previous IP, update needed"
  65. :set previousIPFlex $currentIP
  66.  
  67. # The update URL. Note the "\3F" is hex for question mark (?). Required since ? is a special character in commands.
  68. :local url "http://dynupdate.no-ip.com/nic/update\3Fmyip=$currentIP"
  69. :local noiphostarray
  70. :set noiphostarray [:toarray $noiphost]
  71. :foreach host in=$noiphostarray do={
  72. :log info "No-IP: Sending update for $host"
  73. /tool fetch url=($url . "&hostname=$host") user=$noipuser password=$noippass mode=http dst-path=("no-ip_ddns_update-" . $host . ".txt")
  74. :log info "No-IP: Host $host updated on No-IP with IP $currentIP"
  75.  
  76. # Чистим кеш DNS (вопрос зачем?) если мы не почитим его то тогда команда resolve $noiphost будет бессмысленна . т.к в DNS кеше храниться не правильный IP
  77. /ip dns cache flush
  78.  
  79. }
  80.  
  81.  
  82.  
  83. } else {
  84.  
  85. :log info "otvet ot No-IP: IP $noiphost raven tekushemu na interface $inetinterface, obnovlenie ne trenuetsya"
  86. :log info " ************* close $noiphost *********************" ;
  87. }
  88. }
  89. } else={
  90. :log info "No-IP: $inetinterface is not currently running, so therefore will not update."
  91. :log info " ************* close $noiphost *********************" ;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement