Community discussions

 
ilovepancakes
just joined
Topic Author
Posts: 10
Joined: Thu Oct 04, 2018 4:37 am

User agent with fetch tool

Thu Oct 04, 2018 4:58 am

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") 
}
}
 
tugsynz
just joined
Posts: 3
Joined: Thu Jul 18, 2019 11:09 pm

Re: User agent with fetch tool

Thu Jul 18, 2019 11:26 pm

I'm in the same boat and get the same error, did you manage to find a fix for this?

Cheers,
Tugsynz
 
ilovepancakes
just joined
Topic Author
Posts: 10
Joined: Thu Oct 04, 2018 4:37 am

Re: User agent with fetch tool

Fri Jul 19, 2019 4:44 pm

I'm in the same boat and get the same error, did you manage to find a fix for this?

Cheers,
Tugsynz
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.
 
User avatar
eworm
Member
Member
Posts: 378
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: User agent with fetch tool

Sat Jul 20, 2019 12:21 am

/ tool fetch http-header-field="User-Agent: Mozilla/4.0" ...
Manage RouterOS scripts and extend your devices' functionality: RouterOS Scripts

Who is online

Users browsing this forum: No registered users and 11 guests