Using the following code to try and update my Google DDNS record with current IP, everything seems to work correctly with communicating with Google but Google returns a “badagent” error since the request needs to send a valid user agent to be accepted by Google. How can I set and/or customize a user agent that is sent with the fetch tools URL request?
# Variables
# Username and password are the long cryptic ones Google Domains provides,
# not your regular Google account ones
:local GoogleDNSUsername "gbML26UKGdjm7Oz1"
:local GoogleDNSPassword "ASmwlKjCAkEywaZC"
:local hostName "test.twinstar5.com"
:local currentIP ""
:local setResults ""
:local previousIP ""
# Script
:set currentIP [/ip cloud get public-address]
:set previousIP [:resolve "$hostName"]
:if ($currentIP != $previousIP) do={
:do {
/tool fetch url="https://$GoogleDNSUsername:$GoogleDNSPassword@domains.google.com/nic/update?hostname=$hostName&myip=$currentIP" mode=https dst-path=GoogleDNS.txt
:set setResults [/file get GoogleDNS.txt contents];
:log info ("GoogleDNS said this: $setResults")
} on-error={
:log error ("GoogleDNS: script failed to set new IP address")
}
}
No, unfortunately. I still don’t believe there is a way to add or customize a user agent for requests, although I have not tried to do it again on the latest versions of Router OS.
HTTP_USER_AGENT: Mikrotik/6.x Fetch, Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0
Seems to be no chance to replace, just add to “Mikrotik/6.x Fetch”