Community discussions

MikroTik App
 
ilovepancakes
newbie
Topic Author
Posts: 25
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
newbie
Topic Author
Posts: 25
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
Forum Guru
Forum Guru
Posts: 1071
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" ...
 
digitik
just joined
Posts: 3
Joined: Tue Sep 11, 2018 11:54 am

Re: User agent with fetch tool

Wed Nov 27, 2019 1:22 pm

Code: Select all

/tool fetch url="http://example.com/" http-header-field="User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0"

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"
 
seedbedUnmoved
just joined
Posts: 4
Joined: Mon Jul 27, 2020 6:53 pm

Re: User agent with fetch tool

Mon Jul 27, 2020 8:22 pm

Sorry to resurrect an old thread but how did you get it to append? I used that exact line and it came back as 'Mikrotik/6.x Fetch' I'm on 6.47.1

Command:
/tool fetch url="http://postman-echo.com/get" http-header-field="User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0"

Results:
{"args":{},"headers":{"x-forwarded-proto":"http","x-forwarded-port":"80","host":"postman-echo.com","x-amzn-trace-id":"Root=1-5f1f0b8a-fc7505a8e28e38802ca59cf8","user-agent":"Mikrotik/6.x Fetch"},"url":"http://postman-echo.com/get"}

http://postman-echo.com/get just returns what it gets
 
alexwoo
just joined
Posts: 1
Joined: Sat Sep 23, 2023 2:19 pm

Re: User agent with fetch tool

Mon Sep 25, 2023 6:08 pm

Sorry to resurrect an old thread but how did you get it to append? I used that exact line and it came back as 'Mikrotik/6.x Fetch' I'm on 6.47.1

Command:
/tool fetch url="http://postman-echo.com/get" http-header-field="User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0"

Results:
{"args":{},"headers":{"x-forwarded-proto":"http","x-forwarded-port":"80","host":"postman-echo.com","x-amzn-trace-id":"Root=1-5f1f0b8a-fc7505a8e28e38802ca59cf8","user-agent":"Mikrotik/6.x Fetch"},"url":"http://postman-echo.com/get"}

http://postman-echo.com/get just returns what it gets
Just use `http-header-field="user-agent: useragent"`
> :put ([/tool fetch url="http://postman-echo.com/get" http-header-field="user-agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0" output=user]->"data")
      status: finished
  downloaded: 0KiBC-z pause]
        data: { "args": {}, "headers": { "x-forwarded-proto": "http", "x-forwarded-port": "80", "host": "postman-echo.com", "x-amzn-trace-id": "Root=1-6511a09c-59322be6549949c957d1ae2c", "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0" }, "url": "http://postman-echo.com/get" }

Who is online

Users browsing this forum: No registered users and 3 guests