mheezand

Mikrotik openDNS dynamic IP

Jul 12th, 2020
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. #--------------- Change Values in this section to match your setup ------------------
  2. # User account info of OpenDNS
  3. # Update-only password (obtained from OpenDNS Support). With two-factor authentication enabled, the use of an update only password is required.
  4.  
  5. :local odnsuser "OpenDNS user/email"
  6. :local odnspass "OpenDNS Password"
  7.  
  8. # Set the hostname or label of network to be updated. This is the name of your OpenDNS network on the Dashboard.
  9. # Hostnames with spaces are unsupported. Replace the value in the quotations below with your host name.
  10. # Only one host is supported
  11. # Use "all.dnsomatic.com" for the matichost to update all items in dnsomatic with this IP.
  12.  
  13. # Note, you must have admin or edit (Read/Write/Grant in the OpenDNS Dashboard) to update IP addresses.
  14.  
  15. :local odnshost "YourNetworkName"
  16.  
  17. # Change to the name of interface that gets the changing IP address
  18. # May not be needed for your model number - commenting out this line may still work for single interface devices or if this is not supplied in the DNS-O-Matic script currently being used
  19.  
  20. :local inetinterface "Your Public Interface"
  21.  
  22. #------------------------------------------------------------------------------------
  23. # No more changes needed, one optional change
  24. :global previousIP;
  25. #:log info "Fetching current IP"
  26.  
  27. # Get the current public IP using DNS-O-Matic service.
  28. # or your own link
  29. :local IPHost "http://myip.dnsomatic.com"
  30.  
  31. :log info "Fetching current IP with $IPHost"
  32.  
  33. /tool fetch url="$IPHost" mode=http dst-path=mypublicip.txt
  34.  
  35. # Read the current public IP into the currentIP variable.
  36. :local currentIP [/file get mypublicip.txt contents]
  37. :log info "Fetched current IP as $currentIP"
  38.  
  39. # --------- Optional check to only run if the IP has changed (one line: :if)
  40.  
  41. # to disable, set line below to: ":if ($currentIP != 1) do={"
  42.  
  43. :if ($currentIP != $previousIP) do={
  44. :log info "OpenDNS: Update needed"
  45. :set previousIP $currentIP
  46.  
  47. # The update URL. Note the "\3F" is hex for question mark (?). Required since ? is a special character in commands.
  48. # Some older editions of the MicroTik/WinBox OS require the following line instead (http) whereas newer versions require https.
  49. # :local url "http://updates.opendns.com/nic/update\3Fhostname=$odnshost"
  50.  
  51. :local url "http://updates.opendns.com/nic/update\3Fhostname=$odnshost"
  52. :log info "OpenDNS: Sending update for $odnshost"
  53.  
  54. /tool fetch url=($url) user=$odnsuser password=$odnspass mode=http dst-path=("/net_odns.txt")
  55.  
  56. :delay 2;
  57. :local odnsReply [/file get net_odns.txt contents];
  58. :log info "OpenDNS update complete."
  59. :log info "OpenDNS reply was $odnsReply";
  60.  
  61. } else={
  62. :log info "OpenDNS: Previous IP $previousIP and current IP equal, no update need"
  63. }
Add Comment
Please, Sign In to add comment