bot_detection 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bot_detection.gemspec +21 -0
- data/lib/bot_detection/google_user_agents.rb +21 -0
- data/lib/bot_detection/instance_methods.rb +47 -0
- data/lib/bot_detection/version.rb +3 -0
- data/lib/bot_detection.rb +15 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dd324aace4b5b9a7794dcc63f2dd5ccf7386ce14
|
4
|
+
data.tar.gz: bcef9bccf32832a01cac75298b33f4fe8b1e9ab6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d4d1abf849e52e06f8ad5d31d985f7c2ba4330b7d2b89db720e4960421fcafcfbb771fcb84b755dffa3e35d12400bb94861a90a07c9d0dadfd714171135521b7
|
7
|
+
data.tar.gz: 37bc511a6635e5e0bf8d2b339a0cb578fd36aeca5a2c38091880365f489766c2bae3018995e2d53a0d65baa0a606b904b213b896503f81eab4968e37500065d4
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Nils Berenbold
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# BotDetection
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'bot_detection'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install bot_detection
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/bot_detection/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bot_detection/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bot_detection"
|
8
|
+
spec.version = BotDetection::VERSION
|
9
|
+
spec.authors = ["Nils Berenbold"]
|
10
|
+
spec.email = ["nils.berenbold@gmail.com"]
|
11
|
+
spec.summary = %q{Detects Search Engine crawlers by reverse DNS lookups.}
|
12
|
+
spec.homepage = "http://www.nilsberenbold.de"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
BotDetection::GOOGLE_USER_AGENTS = [
|
2
|
+
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
|
3
|
+
"Googlebot/2.1 (+http://www.google.com/bot.html)",
|
4
|
+
"Googlebot-News",
|
5
|
+
"Googlebot-Image/1.0",
|
6
|
+
"Googlebot-Video/1.0",
|
7
|
+
"(compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)",
|
8
|
+
"Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
|
9
|
+
"(compatible; Mediapartners-Google/2.1; +http://www.google.com/bot.html)",
|
10
|
+
"Mediapartners-Google",
|
11
|
+
"AdsBot-Google (+http://www.google.com/adsbot.html)",
|
12
|
+
"Googlebot",
|
13
|
+
"Googlebot-News (Googlebot)",
|
14
|
+
"Googlebot-Image (Googlebot)",
|
15
|
+
"Googlebot-Video (Googlebot)",
|
16
|
+
"Googlebot-Mobile",
|
17
|
+
"Mediapartners-Google",
|
18
|
+
"Mediapartners (Googlebot)",
|
19
|
+
"Mediapartners-Google Mediapartners (Googlebot)",
|
20
|
+
"AdsBot-Google"
|
21
|
+
]
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'bot_detection'
|
2
|
+
require_relative 'google_user_agents.rb'
|
3
|
+
|
4
|
+
module BotDetection::InstanceMethods
|
5
|
+
def is_search_engine_crawler? options = {}
|
6
|
+
remote_ip = options.delete(:ip) || options.delete(:ip_address) || request.remote_ip
|
7
|
+
return false if remote_ip.blank? || (!is_google? && !is_yahoo? && !is_msn? && !is_bing?)
|
8
|
+
|
9
|
+
return true if options.delete(:development)
|
10
|
+
|
11
|
+
found = false
|
12
|
+
host = get_hostname(remote_ip)
|
13
|
+
["crawl.yahoo.net", "googlebot", "search.msn.com", "ask.com"].each do |h|
|
14
|
+
found = true and break if host.include?(h)
|
15
|
+
end
|
16
|
+
|
17
|
+
return false unless found
|
18
|
+
|
19
|
+
host_ip = get_hostip(host)
|
20
|
+
return host_ip == remote_ip
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
24
|
+
def is_google?
|
25
|
+
BotDetection::GOOGLE_USER_AGENTS.include?(request.env['HTTP_USER_AGENT']) || request.user_agent.downcase.include?("googlebot")
|
26
|
+
end
|
27
|
+
|
28
|
+
def is_yahoo?
|
29
|
+
request.user_agent.downcase.include?("yahoo! slurp")
|
30
|
+
end
|
31
|
+
|
32
|
+
def is_msn?
|
33
|
+
request.user_agent.downcase.include?("msnbot")
|
34
|
+
end
|
35
|
+
|
36
|
+
def is_bing?
|
37
|
+
request.user_agent.downcase.include?("bing")
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_hostname(ip_address)
|
41
|
+
Socket.gethostbyaddr(ip_address.split(".").map(&:to_i).pack("CCCC")).first
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_hostip(host)
|
45
|
+
Socket.gethostbyname(host).last.unpack("C*").join(".")
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "bot_detection/version"
|
2
|
+
|
3
|
+
module BotDetection
|
4
|
+
def self.included(target)
|
5
|
+
target.send(:include, BotDetection::InstanceMethods)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'bot_detection/instance_methods'
|
10
|
+
|
11
|
+
class ActionController::Base
|
12
|
+
include BotDetection
|
13
|
+
end
|
14
|
+
|
15
|
+
ActionView::Base.send :include, BotDetection::InstanceMethods
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bot_detection
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nils Berenbold
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- nils.berenbold@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bot_detection.gemspec
|
54
|
+
- lib/bot_detection.rb
|
55
|
+
- lib/bot_detection/google_user_agents.rb
|
56
|
+
- lib/bot_detection/instance_methods.rb
|
57
|
+
- lib/bot_detection/version.rb
|
58
|
+
homepage: http://www.nilsberenbold.de
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.2.1
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Detects Search Engine crawlers by reverse DNS lookups.
|
82
|
+
test_files: []
|