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
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.
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.
Have you thought about using the .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.
Hi.
Is it possible, that GoDaddy changed something, because from 30.5. I get an error
Download from api.godaddy.com FAILED: Fetch failed with status 403
Is it only me or also others?
Thank you for reaching out to us regarding the recent changes to our Domain API.
We wanted to inform you that we have recently updated our Domain API requirements. As part of this update, customers are now required to have 50 or more domains in their account to utilize the API. Unfortunately, as you currently only have 1 domain in your account, access to the API is blocked for you.
However, we want to assure you that you still have access to the OTE API without any blocks.
We apologize for any confusion or inconvenience this may have caused. If you have any further questions or need assistance with any other aspect of our services, please don’t hesitate to reach out.