Last active
April 21, 2019 17:07
-
-
Save gcormier/1e9c2a10a8a7b112b8f3c216fc1ac093 to your computer and use it in GitHub Desktop.
Update OpenDNS with Mikrotik IP for custom dns settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:local odnsuser "[email protected]" | |
:local odnspass "password12345!" | |
# Set the hostname or label of network to be updated. This is the name of your OpenDNS network on the Dashboard. | |
# Note, you must have admin or edit (Read/Write/Grant in the OpenDNS Dashboard) to update IP addresses. | |
:local odnshost "Strand" | |
# 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 | |
:local inetinterface "ether1" | |
#------------------------------------------------------------------------------------ | |
# No more changes needed, one optional change | |
:global previousIP; | |
:log info "Fetching current IP" | |
# Get the current public IP using DNS-O-Matic service. | |
/tool fetch url="http://myip.dnsomatic.com/" mode=http dst-path=mypublicip.txt | |
# Read the current public IP into the currentIP variable. | |
:local currentIP [/file get mypublicip.txt contents] | |
:log info "Fetched current IP as $currentIP" | |
:if ($currentIP != $previousIP) do={ | |
:log info "OpenDNS: Update needed" | |
:set previousIP $currentIP | |
# The update URL. Note the "\3F" is hex for question mark (?). Required since ? is a special character in commands. | |
:local url "https://updates.opendns.com/nic/update\3Fhostname=$odnshost" | |
:log info "OpenDNS: Sending update for $odnshost" | |
/tool fetch url=($url) user=$odnsuser password=$odnspass mode=http dst-path=("/net_odns.txt") | |
:delay 2; | |
:local odnsReply [/file get net_odns.txt contents]; | |
:log info "OpenDNS update complete." | |
:log info "OpenDNS reply was $odnsReply"; | |
} else={ | |
:log info "OpenDNS: Previous IP $previousIP and current IP equal, no update need" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment