cURL is a really useful tool for Linux users. This tool can easily download all the files from the internet over lots of supported protocols – FTP, HTTPS, IMAP, POP3, RTSP, SMB, SMTP, SCP, DICT etc. and lot more. That’s why it’s my favorite tool to download files from the internet instead of “wget”. When you use cURL, the server sees you as a browser requesting file access. Now, let’s take a look how to change the user agent of cURL.
When connecting to the server, the program sends a data like this – “Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0”. The server identifies that you’re using Firefox (although you’re not). You can set out the option of your favorite browser as user-agent of the cURL tool.
Changing the user-agent
In cURL, the syntax for changing the user-agent follows this structure –
curl -A "user-agent-name-here" url curl --user-agent "user-agent-name-here" url curl -H "User-Agent: user-Agent-Name-Here"
The user agent also follows this structure –
Mozilla/[version] ([system and browser information]) [platform] ([platform details]) [extensions]
In this command line example, I’ll be using Firefox as the user-agent of cURL for connecting with OSRadar.
$ curl -A "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0" https://www.osradar.com/ $ curl -I -A "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0" https://www.osradar.com/
If you want to use your user-agent as Safari, use this command line –
curl -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (K HTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" https://www.osradar.com/