Advertisement
Guest User

dydns_routerOS_6.x

a guest
Dec 23rd, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. #No-IP automatic Dynamic DNS update for RouterOS v6.x
  2.  
  3. #--------------- Change Values in this section to match your setup ------------------
  4.  
  5. # No-IP User account info
  6. :local noipuser "YOUR_LOGIN_TO_NO_IP"
  7. :local noippass "YOUR_PASSWORD_TO NO_IP"
  8.  
  9. # Workaround - find IP of a single dynamic host for IP prior to update
  10. # Only enter a single hostname for this variable
  11. :local previphost "YOUR_HOST.no-ip.org"
  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 "YOUR_HOST.no-ip.org,YOUR_HOST.no-ip.com"
  17.  
  18. # Change to the name of interface that gets the dynamic IP address
  19. :local inetinterface "YOUR_WAN_INTERFACE_NAME_f.e_port2_public"
  20.  
  21. #------------------------------------------------------------------------------------
  22. # No more changes need
  23.  
  24. :global previousIP
  25.  
  26. :if ([/interface get $inetinterface value-name=running]) do={
  27.  
  28. # get the current IP address from the internet (in case of double-nat)
  29. /tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="dyndns.checkip.html"
  30. :local result [/file get dyndns.checkip.html contents]
  31.  
  32. # parse the current IP result
  33. :local resultLen [:len $result]
  34. :local startLoc [:find $result ": " -1]
  35. :set startLoc ($startLoc + 2)
  36. :local endLoc [:find $result "</body>" -1]
  37. :local currentIP [:pick $result $startLoc $endLoc]
  38. :log info "Update NO-IP.com: currentIP = $currentIP"
  39.  
  40. # Get the current IP on the interface
  41. # :local currentIP [/ip address get [find interface="$inetinterface" disabled=no] address]
  42.  
  43. # Strip the net mask off the IP address
  44. # :for i from=( [:len $currentIP] - 1) to=0 do={
  45. # :if ( [:pick $currentIP $i] = "/") do={
  46. # :set currentIP [:pick $currentIP 0 $i]
  47. # }
  48. # }
  49.  
  50. # Get your previous IP address
  51. :set previousIP [:resolve $previphost]
  52.  
  53. :if ($currentIP != $previousIP) do={
  54. :log info "No-IP: Current IP $currentIP is not equal to previous IP $previousIP, update needed"
  55. :set previousIP $currentIP
  56.  
  57. # The update URL. Note the "\3F" is hex for question mark (?). Required since ? is a special character in commands.
  58. :local url "https://dynupdate.no-ip.com/nic/update\3Fmyip=$currentIP"
  59. :local noiphostarray
  60. :set noiphostarray [:toarray $noiphost]
  61. :foreach host in=$noiphostarray do={
  62. :log info "No-IP: Sending update for $host"
  63. /tool fetch url=($url . "&hostname=$host") user=$noipuser password=$noippass mode=https keep-result=no;
  64. :log info "No-IP: Host $host updated on No-IP with IP $currentIP"
  65. }
  66. } else={
  67. :log info "No-IP: Previous IP $previousIP is equal to current IP, no update needed"
  68. }
  69. } else={
  70. :log info "No-IP: $inetinterface is not currently running, so therefore will not update."
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement