Community discussions

MikroTik App
 
tristanwalter
just joined
Topic Author
Posts: 5
Joined: Wed Aug 03, 2016 6:37 am

GoDaddy Dynamic DNS

Mon Jul 09, 2018 7:14 pm

New to Mikrotik scripting and looking for help. I have a PowerShell script I want to convert to a Mikrotik script. The script is to update IP for GoDaddy hosted domain. I'd like to pull the IP address from the interface rather then an external site.
$domain = 'your.domain.to.update'  # your domain
$name = 'name_of_host' #name of the A record to update
$key = 'key' #key for godaddy developer API
$secret = 'Secret' #Secret for godday developer API

$headers = @{}
$headers["Authorization"] = 'sso-key ' + $key + ':' + $secret
$result = Invoke-WebRequest https://api.godaddy.com/v1/domains/$domain/records/A/$name -method get -headers $headers
$content = ConvertFrom-Json $result.content
$dnsIp = $content.data

# Get public ip address there are several websites that can do this.
$currentIp = Invoke-RestMethod http://ipinfo.io/json | Select -exp ip

if ( $currentIp -ne $dnsIp) {
    $Request = @{ttl=3600;data=$currentIp }
    $JSON = Convertto-Json $request
    Invoke-WebRequest https://api.godaddy.com/v1/domains/$domain/records/A/$name -method put -headers $headers -Body $json -ContentType "application/json"
}
Alternatively here it is as a bash script
domain=""   # your domain
name=""     # name of A record to update
key=""      # key for godaddy developer API
secret=""   # secret for godaddy developer API

headers="Authorization: sso-key $key:$secret"

# echo $headers

result=$(curl -s -X GET -H "$headers" \
 "https://api.godaddy.com/v1/domains/$domain/records/A/$name")

dnsIp=$(echo $result | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
# echo "dnsIp:" $dnsIp

# Get public ip address there are several websites that can do this.
ret=$(curl -s GET "http://ipinfo.io/json")
currentIp=$(echo $ret | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
# echo "currentIp:" $currentIp

 if [ $dnsIp != $currentIp ];
 then
#	echo "Ips are not equal"
	request='{"data":"'$currentIp'","ttl":3600}'
#	echo $request
	nresult=$(curl -i -s -X PUT \
 -H "$headers" \
 -H "Content-Type: application/json" \
 -d $request "https://api.godaddy.com/v1/domains/$domain/records/A/$name")
#	echo $nresult
fi
 
tristanwalter
just joined
Topic Author
Posts: 5
Joined: Wed Aug 03, 2016 6:37 am

Re: GoDaddy Dynamic DNS

Mon Jul 09, 2018 9:08 pm

will using the following syntax use the variables?

:local headers "Authorization: sso-key $usrkey:$usrsecret"
 
tristanwalter
just joined
Topic Author
Posts: 5
Joined: Wed Aug 03, 2016 6:37 am

Re: GoDaddy Dynamic DNS

Mon Jul 09, 2018 10:01 pm

Does anyone know a way to send a custom header like the -H function for curl using Mikrotik Fetch tool?
 
tristanwalter
just joined
Topic Author
Posts: 5
Joined: Wed Aug 03, 2016 6:37 am

Re: GoDaddy Dynamic DNS

Thu Jul 12, 2018 9:15 pm

Found DomainConnect DDNS that'll run on local machines as it appears MikroTik Fetch tool doesn't yet support editing headers which is required for authentication with GoDaddy api. I have written everything for Mikrotik so hopefully when header editing is added I can add the necessary commands.
 
nansenat16
just joined
Posts: 1
Joined: Fri Aug 02, 2019 5:55 pm

Re: GoDaddy Dynamic DNS

Fri Aug 02, 2019 6:23 pm

 
tristanwalter
just joined
Topic Author
Posts: 5
Joined: Wed Aug 03, 2016 6:37 am

Re: GoDaddy Dynamic DNS

Mon Aug 05, 2019 5:35 pm

Thank you nansenat16 for the example. I see that since 6.44 http-header-field has been added. I had been busy correcting issues with the 6.44.x updates that I haven't noticed the fetch changes.
 
Tdaddysimi
Member Candidate
Member Candidate
Posts: 108
Joined: Wed Sep 28, 2016 4:37 pm
Location: Minnesota

Re: GoDaddy Dynamic DNS

Wed Aug 07, 2019 5:33 pm

Any update on this? I have a couple godaddy domains i'd like my tik to auto update to.
 
jdodge
just joined
Posts: 2
Joined: Mon Aug 05, 2019 11:05 pm

Re: GoDaddy Dynamic DNS

Mon Aug 12, 2019 9:13 pm

Have you thought about using the <your mac here>.sn.mynetname.net built into the OS under IP > Cloud?
For instance if you own stuff.net as a godaddy (ugh!) domain and wanted omaha.stuff.net to resolve to your router's wan - you use Mikrotik's built in myname.net address as a cname target.
Let's say yours is 830708af0128.sn.myname.net -- you then create a cname for omaha.stuff.net and point it to 830708af0128.sn.myname.net. It's what I've been doing for a while now -- works with any DNS provider, even one that doesn't natively support DDNS entries and updating. I have not as of yet had a problem with it. If you replace the router -- you have a new mac/address - you just update your cname entry to the new one. If you change DNS provider -- it's a simple move -- no client change.
 
carlosedp
just joined
Posts: 1
Joined: Mon Oct 12, 2020 7:00 pm

Re: GoDaddy Dynamic DNS

Mon Oct 12, 2020 7:03 pm

I've updated the script posted above to a simpler logic where the current IP is fetched from a public IP service and updated accordingly:
#GoDaddy DDNS Update Script
#Tested with RouterOS 6.45.2 (Minimum version RouterOS 6.44)
#Date:2020/10/12
#The script requires "read,write,policy,test" policies to work with global variables.

#Create Schedule running
# /system scheduler add name=update-ddns interval=10m on-event=godaddy-ddns

:local Domain "Domain"
:local Hostname "Hostname"
:local APIKey "GoDaddy Key"
:local APISecret "GoDaddy Secret"

# DDNS Params
:local ddnsURL "https://api.godaddy.com/v1/domains/$Domain/records/A/$Hostname"

# Get current IP
:global currentIP
:local IPGetURL "https://ipecho.net/plain"
:local result [/tool fetch url=$IPGetURL http-method=get as-value output=user]

:if ($result->"status" = "finished") do={
    :set currentIP ($result->"data")
} else={
    :log error ("DDNS: Error getting current IP from $IPGetURL")
    :err "Error getting current IP"
}

#Store global variable to check if update is required
:global lastConfiguredIP
:if ([:typeof [:global lastConfiguredIP]] = nil ) do={ :global lastConfiguredIP 0.0.0.0 } else={ :set lastConfiguredIP $lastConfiguredIP }

:if ($currentIP != $lastConfiguredIP) do={
    :log info "DDNS: Updating $Hostname.$Domain to use IP: $currentIP"
    :local ddnsipjson "[{\"type\":\"A\", \"name\":\"$Hostname\", \"data\":\"$currentIP\", \"ttl\":3600}]"
    :local result [/tool fetch url=$ddnsURL http-method=put http-data=$ddnsipjson http-header-field="content-type: application/json,Authorization: sso-key $APIKey:$APISecret" as-value output=user]
    :if ($result->"status" = "finished") do={
        :log info ("DDNS: Configured domain $Hostname.$Domain to IP $currentIP.")
        :global lastConfiguredIP $currentIP
    } else={
        :log error ("DDNS: Error setting domain $Hostname.$Domain to IP $currentIP. $result->status")
    }
} else={
    :log info "DDNS: Domain $Hostname.$Domain current IP $currentIP not changed. Not updated."
}
This does not depend on configuring the valid IP on a local interface, like in cases where the router access the internet thru another bridge.

Who is online

Users browsing this forum: No registered users and 71 guests