Advertisement
karanik

mikrotik_no-ip2

Oct 13th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #Dynamic DNS Update Script for No-IP DNS behind nat
  2. # Set needed variables
  3. :local username "MY"
  4. :local password "MY"
  5. :local host "MY.ddns.net"
  6. :global previousIP
  7. # print some debug info
  8. :log info ("Update No-IP DNS: username = $username")
  9. :log info ("Update No-IP DNS: hostname = $host")
  10. :log info ("Update No-IP DNS: previousIP = $previousIP")
  11. #
  12. # behind nat - get the public address using dyndns url http://checkip.dyndns.org
  13. /tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
  14. :delay 2
  15. :local result [/file get dyndns.checkip.html contents]
  16. :log info "dyndns result = $result"
  17. # parse the current IP result
  18. :local resultLen [:len $result]
  19. :local startLoc [:find $result ": " -1]
  20. :set startLoc ($startLoc + 2)
  21. :local endLoc [:find $result "</body>" -1]
  22. :local currentIP [pick $result $startLoc $endLoc]
  23. :log info "No-IP DNS: currentIP = $currentIP"
  24. :if ($currentIP != $previousIP) do={
  25. :log info "No-IP: Current IP $currentIP is not equal to previous IP, update needed"
  26. :set previousIP $currentIP
  27. :local url "http://dynupdate.no-ip.com/nic/update/?myip=$currentIP&hostname=$host"
  28. :log info "No-IP DNS: Sending update for $host"
  29. /tool fetch url=$url user=$username password=$password mode=http dst-path=("no-ip_ddns_update.txt")
  30. :log info "No-IP DNS: Host $host updated on No-IP with IP $currentIP"
  31. :delay 2
  32. :local result [/file get "no-ip_ddns_update.txt" contents]
  33. :log info "Update Result = $result"
  34. } else={
  35. :log info "No-IP: update not needed "
  36. }
  37. # end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement