Linux http user agent

User-Agent

User-Agent заголовок запроса является характеристикой строки , которая позволяет сервера и сетевые коллеги идентификации приложения, операционную системе, поставщику и / или версии запрашивающего агента пользователя .

Предупреждение. Прочтите раздел «Обнаружение браузера с помощью пользовательского агента», чтобы узнать, почему обслуживание разных веб-страниц или служб в разных браузерах обычно является плохой идеей.

Syntax

User-Agent: product> / product-version> comment> 

Общий формат для веб-браузеров:

User-Agent: Mozilla/5.0 (system-information>) platform> (platform-details>) extensions> 

Directives

Идентификатор продукта-его название или кодовое имя разработки.

Ноль или более комментариев,содержащих более подробную информацию.Например,информация о субпродукте.

строка Firefox UA

Дополнительные сведения о строках пользовательских агентов на основе Firefox и Gecko см. В справочнике по строкам пользовательских агентов Firefox . Строка UA Firefox разбита на 4 компонента:

Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion
  1. Mozilla/5.0 — это общий токен, который говорит о том, что браузер совместим с Mozilla. По историческим причинам почти каждый браузер сегодня его отправляет.
  2. платформа описывает родную платформу, на которой работает браузер (Windows, Mac, Linux, Android и т. д.), и является ли это мобильным телефоном. Телефоны с ОС Firefox говорят: Mobile — Интернет — это платформа. Обратите внимание, чтоплатформа может состоять из несколькихтокенов ; Подробности и примеры см. ниже.
  3. rv: geckoversion указывает версию выпуска Gecko (например, « 17.0 »). В последних версиях браузеров geckoversion совпадает с firefoxversion .
  4. Gecko / geckotrail указывает, что браузер основан на Gecko. (На рабочем столеgeckotrail всегда является фиксированной строкой 20100101 . )
  5. Firefox / firefoxversion указывает, что это браузер Firefox, и предоставляет версию (например, « 17.0» ).

Examples

Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0 Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0 

струна Chrome UA

Строка пользовательского агента Chrome (или движков на основе Chromium/Blink) аналогична строке Firefox. Для совместимости он добавляет такие строки, как KHTML, like Gecko и Safari .

Examples

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36 

Струна Opera UA

Браузер Opera также основан на движке Blink, поэтому он выглядит почти так же, как строка Chrome UA, но добавляет «OPR/» .

Читайте также:  Math in linux kernel

Examples

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41 

Использовались более старые выпуски Opera на базе Presto:

Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/10.00 Opera/9.60 (Windows NT 6.0; U; en) Presto/2.1.1

Строка Microsoft Edge UA

Браузер Edge также основан на движке Blink. Он добавляет «Edg/» .

Examples

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.59 

строка Safari UA

В этом примере строка пользовательского агента — это мобильная версия Safari. В нем есть слово «Mobile» .

Examples

Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Mobile/15E148 Safari/604.1 

Строка Internet Explorer UA

Examples

Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)

струны Crawler and bot UA

Examples

Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) 
Mozilla/5.0 (compatible; YandexAccessibilityBot/3.0; +http://yandex.com/bots) 

Строки UA библиотек и сетевых инструментов

Examples

Источник

Как установить или изменить User-Agent с помощью curl

img

Строка User-Agent (UA) — это информация, включенная в заголовок HTTP, действующая от имени пользователя. Когда вы подключаетесь к веб-сайту из браузера, UA сообщает веб-сайту, из какого браузера поступает запрос, его номер версии и операционную систему.

Сервер может по-разному реагировать на определенных пользовательских агентов. Следовательно, вам может потребоваться изменить строку UA.

В этом руководстве вы узнаете, как установить или изменить пользовательский агент с помощью curl.

Как установить или изменить User-Agent с помощью curl

Curl User Agent

Когда вы используете curl для отправки HTTP-запроса, он отправляет информацию пользовательского агента в формате curl/version.number .

Последняя стабильная версия на момент написания — 7.72. 0. Следовательно, строка UA в HTTP-запросе будет: curl/7.72.0 .

Есть несколько способов установить или изменить пользовательский агент с помощью команды curl .

Изменить User-Agent с помощью curl

Чтобы изменить пользовательский агент curl на другой браузер, добавьте параметр -A с нужной строкой пользовательского агента:

curl -A "user-agent-name-here" [URL]

Чтобы отправить запрос на веб-страницу example.com путем эмуляции пользовательского агента Firefox 81, вы должны запустить:

curl -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0" https://example.com/"

Вы также можете использовать параметр —user-agent со следующим синтаксисом команды:

curl --user-agent "user-agent-name-here" url

В качестве альтернативы запустите параметр командной строки -H , который принимает один параметр дополнительного заголовка для включения в запрос curl:

curl -H "User-Agent: user-Agent-Name-Here"

Итог

Теперь вы должны знать, как изменить пользовательский агент с помощью curl и установить в нем нужный браузер. Это позволяет обойти возможные блокировки или изменения содержимого, которые могут появиться из-за использования curl.

Читайте также:  Невозможно запустить приложение astra linux

Источник

How to Set User Agent in curl

A user-agent string describes various info to the server you’re trying to connect to, for example, browser type, browser version, operating system, etc. Whenever you’re browsing the web, your web browser automatically includes these data in the HTTP header. Depending on the user agent, the server may respond differently.

The curl command is a powerful tool for developers to transfer data to and from servers. It’s based on the libcurl development library, compatible with most other libraries. We can use the curl command to imitate different user agents when communicating with a server.

Curl user-agent

The curl command sends its own user agent in the HTTP request by default. The curl user-agent follows the following structure:

To get the version number of curl, use the following command:

As the output reports, it’s v7.68.0. So, the default user agent of curl would look like this:

Setting custom user agent in curl

We can tell curl to send a different user agent string instead. To do so, use the flag “-A” to describe the new user agent. The command structure will look something like this:

The flag “-A” is an abbreviation for the option “–user-agent”. We can also use that for better clarification:

Another method we can use is the flag “-H.” This flag allows tweaking a single parameter of an extra header to be embedded into the curl request. The command structure would look like this:

Getting custom user-agent

Now, it’s a question of getting a custom user agent. Any user agent consists of multiple variables (operating system, browser version, browser type, etc.), each with multiple possible values. This easily pushes the number of possible user agents to millions.

If you’re interested, check out this WhatIsMyBrowser database on numerous user agents. The massive database records millions of unique user agents. For demonstration purposes, I will be using the following user agent string:

$ Mozilla / 5.0 ( X11; Linux x86_64 ) AppleWebKit / 537.36 ( KHTML, like Gecko ) Chrome / 99.0.4844.74 Safari / 537.36

This user-agent describes the following info:

Note that there’s no established standard for defining a user agent. This leads to a very wide (and wild) range of user-agent strings.

Читайте также:  Нет звука линукс убунту

Sending custom user agents using curl

Now that we have our hand on the desired user agent, we will demonstrate how to implement it. In the following example, we’re going to send a request to example.com using our custom user agent string:

$ curl —user-agent «Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36» example.com

Using the verbose mode, we can see additional info curl is sending to the remote server:

$ curl —verbose —user-agent «Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36» example.com

Final Thoughts

This guide demonstrates setting a custom user agent in curl. Depending on the user-agent, the requesting service may respond differently. The curl command sends its own user agent by default. However, it allows specifying a different user agent for its web requests.

This is just a single way of using the curl command. Check out this guide on curl in Linux that demonstrates many ways of using curl (with examples). As always, it’s also recommended to take a look at the man page:

Источник

Change the User Agent in Wget

Networking HowTos

The Wget application is a non-interactive tool to download data from a server using either the HTTP, HTTPS or FTP protocols. This article will focus on the HTTP and HTTPS protocols, as the user agent value has no relevance with the FTP protocol.
There will be times when you need to download a web page, emulating a different browser. Some web sites may output different html code depending on the browser being used to request the page.
By modifying the User Agent header on the http/https request, you can tell the server what browser you are using.
Wget has the ability to modify the user agent value easily, using the “-a” parameter as shown in the example below.
Modifying the User Agent in Wget:

$ wget -U "User Agent Here" "http://website.url.here"

The example below will emulate Internet Explorer 6 requesting the page from www.google.com

$ wget -U "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" "http://www.google.com"
$ wget --user-agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" "http://www.google.com"

If the web page is designed to show different output depending on the browser, the above example would be show the output as though you were connecting to the web server from Internet Explorer 6.
For a list of some of the common user agent strings, please click here.

Источник

Оцените статью
Adblock
detector