Module: BotDetection::InstanceMethods
- Defined in:
- lib/bot_detection/instance_methods.rb
Instance Method Summary collapse
- #get_hostip(host) ⇒ Object
- #get_hostname(ip_address) ⇒ Object
- #is_bing? ⇒ Boolean
- #is_google? ⇒ Boolean
- #is_msn? ⇒ Boolean
- #is_search_engine_crawler?(options = {}) ⇒ Boolean
- #is_yahoo? ⇒ Boolean
Instance Method Details
#get_hostip(host) ⇒ Object
44 45 46 |
# File 'lib/bot_detection/instance_methods.rb', line 44 def get_hostip(host) Socket.gethostbyname(host).last.unpack("C*").join(".") end |
#get_hostname(ip_address) ⇒ Object
40 41 42 |
# File 'lib/bot_detection/instance_methods.rb', line 40 def get_hostname(ip_address) Socket.gethostbyaddr(ip_address.split(".").map(&:to_i).pack("CCCC")).first end |
#is_bing? ⇒ Boolean
36 37 38 |
# File 'lib/bot_detection/instance_methods.rb', line 36 def is_bing? request.user_agent.to_s.downcase.include?("bing") end |
#is_google? ⇒ Boolean
24 25 26 |
# File 'lib/bot_detection/instance_methods.rb', line 24 def is_google? BotDetection::GOOGLE_USER_AGENTS.include?(request.env['HTTP_USER_AGENT']) || request.user_agent.to_s.downcase.include?("googlebot") end |
#is_msn? ⇒ Boolean
32 33 34 |
# File 'lib/bot_detection/instance_methods.rb', line 32 def is_msn? request.user_agent.to_s.downcase.include?("msnbot") end |
#is_search_engine_crawler?(options = {}) ⇒ Boolean
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bot_detection/instance_methods.rb', line 5 def is_search_engine_crawler? = {} remote_ip = .delete(:ip) || .delete(:ip_address) || request.remote_ip return false if remote_ip.blank? || (!is_google? && !is_yahoo? && !is_msn? && !is_bing?) return true if .delete(:development) found = false host = get_hostname(remote_ip) ["crawl.yahoo.net", "googlebot", "search.msn.com", "ask.com"].each do |h| found = true and break if host.include?(h) end return false unless found host_ip = get_hostip(host) return host_ip == remote_ip false end |
#is_yahoo? ⇒ Boolean
28 29 30 |
# File 'lib/bot_detection/instance_methods.rb', line 28 def is_yahoo? request.user_agent.to_s.downcase.include?("yahoo! slurp") end |