Skip to content
/ isbot Public
forked from arp242/isbot

Go library to detect HTTP bots.

License

Notifications You must be signed in to change notification settings

ninibe/isbot

 
 

Repository files navigation

Go library to detect bots based on the HTTP request. A "bot" is defined as any request that isn't a regular browser request initiated by the user. This includes things like web crawlers, but also stuff like "preview" renderers and the like.

Bot() accepts a http.Request since it looks at all information, not just the User-Agent. You can use UserAgent() if you just have a User-Agent, but it's highly recommended to use Bot().

Import as zgo.at/isbot; API docs: https://godocs.io/zgo.at/isbot

There is a command-line tool in cmd/isbot to check if User-Agents are bots:

$ isbot 'Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0' 'Wget/1.13.4 (linux-gnu)'
false (1: NoBotNoMatch) ← Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0
true  (4: BotClientLibrary) ← Wget/1.13.4 (linux-gnu)

It's not 100% reliable, and there are some known cases where it gets things wrong. See isbot_test.go for a list of test cases.

The performance is pretty good; turns out that running a few string.Contains() is loads faster than a (bot|crawler|search|...) regexp.

Updating IP ranges

The cloud provider IP ranges can be updated from the ip-address-databases ASN database:

python update_ip_ranges.py > ip_ranges_gen.go

The script matches providers by ASN name patterns (e.g., "AMAZON", "CLOUDFLARE"). If a provider is renamed and no longer matches, the script will exit with an error prompting you to update the patterns in PROVIDER_PATTERNS.

About

Go library to detect HTTP bots.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 54.1%
  • Python 39.7%
  • Shell 6.2%