User Agent Parser · Tutorial

How to spot bots and browsers in your server logs

6 min readbeginnerUpdated

Your server is busier than your analytics suggest, and you suspect bots. This tutorial extracts User-Agent strings from an access log, pastes them into the parser, and reads the table to tell people from crawlers and scripts.

What you need

  • The User Agent Parser
  • User-Agent lines from your access log, or the sample from the Try it button

Steps

  1. Get the User-Agent lines

    In common Apache and nginx log formats, the User-Agent is the last quoted part of each line. On Linux or macOS you can print just that part with a short command, then copy the result.

    awk -F'"' '{print $6}' access.log | sort | uniq -c | sort -rn | head -50
  2. Paste them into the parser

    Paste one User-Agent per line; remove the counts from the front if you used the command above. With more than one line, the tool shows a table instead of a single result, and a summary of how many are bots.

  3. Read the table

    In the sample, Edge on Windows and Safari on iPhone are people. Googlebot is a search engine crawler, GPTBot an AI crawler and curl a command-line tool. The last Chrome line is a reduced Android string: the phone model is hidden on purpose.

  4. Check a single line in detail

    Paste one line on its own to see its engine, device and notes. For example, Chrome on iPhone shows WebKit as the engine, because all iOS browsers use it.

  5. Decide what to do

    If AI crawlers are using your bandwidth, block them in robots.txt with the robots.txt Generator. For bots that ignore robots.txt, use your host’s firewall or bot protection.

Try it yourself

Opens the User Agent Parser with this tutorial's sample loaded.

Try it now

Common mistakes

Trusting the name alone
Anyone can claim to be Googlebot. To confirm a real search crawler, check its IP address with a reverse DNS lookup, as the search engines describe in their documentation.
Counting every line as a visit
One page view can produce many requests for images and scripts. Count page requests, not every line.
Ignoring empty user agents
Requests with no User-Agent at all are almost always scripts. They show as Unknown in the table.

Next steps

Go back to the User Agent Parser, or keep going with one of these:

FAQ

How many lines can I paste?

Up to 5,000 lines are shown in the table at once.

Are my logs uploaded?

No. Everything is parsed in your browser.