Inidian

ChangeIP Mikrotik Script

Sep 21st, 2014
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. # HomingBeacon Main Dynamic DNS Update Script
  2. # Written by Sam Norris, ChangeIP.com
  3. # 20100728 Tested on RouterOS 4.9
  4. # 20110511 Tested on RouterOS 5.2
  5.  
  6. # Set your specific ChangeIP.com preferences here.
  7. :global ddnsuser "USERNAME"
  8. :global ddnspass "PASS"
  9. :global ddnshost "HOST"
  10. # Change ddnsport to 8245 to bypass proxy.
  11. :local ddnsport 80
  12.  
  13. # Do not edit anything below this line. You have been warned.
  14. # Abusive updates to the system will cause firewall blocks.
  15.  
  16. # Please be considerate and
  17. # do not let this script run more than once per 3-5 minutes.
  18.  
  19. :log info "DDNS: Starting."
  20.  
  21. # Initialize checkpoint
  22. :global ddnscheckpoint
  23. :if ([:typeof $ddnscheckpoint] = "time") do={
  24. :log info ("DDNS: Last check was " . ([/system clock get time] - $ddnscheckpoint))
  25. } else={
  26. :log info "DDNS: Cannot determine checkpoint, set now."
  27. :global ddnscheckpoint ( [/system clock get time] - 1d )
  28. }
  29.  
  30. # Get the current IP
  31. :if ([/system clock get time] - $ddnscheckpoint > [:totime 180s] || [/system clock get time] - $ddnscheckpoint < [:totime 0s]) do={
  32. :log info "DDNS: Performing remote IP detection."
  33. /tool fetch address="ip.changeip.com" host="ip.changeip.com" src-path=("/?" . [/int eth get 0 mac-address ]) dst-path="ip.changeip.com.txt" mode=http port=$ddnsport
  34. :global ddnscheckpoint [/system clock get time]
  35. } else={
  36. :log info "DDNS: Please be considerate and wait a few seconds longer."
  37. :break
  38. }
  39.  
  40. # Parse the IP address received from fetch script.
  41. :global ddnslastip
  42. :local html [/file get "ip.changeip.com.txt" contents]
  43. :local ddnsip [:pick $html ([:find $html "<!--IPADDR="] + 11) [:find $html "-->"] ]
  44.  
  45. # Is it a valid IP and is it different than the last one?
  46. :if ([:typeof [:toip $ddnsip]] = "ip" AND $ddnsip != $ddnslastip ) do={
  47. :log info "DDNS: Sending UPDATE with $ddnsip"
  48. :log info [/tool dns-update name=$ddnshost address=$ddnsip key-name=$ddnsuser key=$ddnspass ]
  49. :global ddnslastip $ddnsip
  50. } else={
  51. :log info "DDNS: No update required."
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment