Module: Ronin::Web::UserAgents

Defined in:
lib/ronin/web/user_agents.rb,
lib/ronin/web/user_agents/chrome.rb,
lib/ronin/web/user_agents/firefox.rb,
lib/ronin/web/user_agents/version.rb,
lib/ronin/web/user_agents/data_dir.rb,
lib/ronin/web/user_agents/os/linux.rb,
lib/ronin/web/user_agents/os/mac_os.rb,
lib/ronin/web/user_agents/google_bot.rb,
lib/ronin/web/user_agents/os/android.rb,
lib/ronin/web/user_agents/os/windows.rb,
lib/ronin/web/user_agents/internet_archive.rb

Overview

Provides categories of common User-Agent strings.

Example

Get a random User-Agent string:

user_agent = Ronin::Web::UserAgents.random
# => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.230 Safari/537.36"

Get a random Chrome User-Agent string:

user_agent = Ronin::Web::UserAgents.chrome.random
# => "Mozilla/5.0 (Linux; Android 5.1.1; Redmi Note 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4688.3 Mobile Safari/537.36"

Get a random Firefox User-Agent string:

user_agent = Ronin::Web::UserAgents.firefox.random
# => "Mozilla/5.0 (Windows NT 6.1; rv:78.0.2) Gecko/20100101 Firefox/78.0.2"

Get a random GoogleBot User-Agent string:

user_agent = Ronin::Web::UserAgents.google_bot.random
# => "GoogleBot/2.1 (+http://www.google.com/bot.html)"

Defined Under Namespace

Modules: Chrome, Firefox, GoogleBot, InternetArchive, OS

Constant Summary collapse

VERSION =

ronin-web-user_agents version

'0.1.0'
DATA_DIR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Path to the data/ directory.

File.expand_path('../../../../data',__dir__)

Class Method Summary collapse

Class Method Details

.chromeChrome

Google Chrome User-Agent strings.

Examples:

user_agent = Ronin::Web::UserAgents.chrome.random
# => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.2495.20 Safari/537.36"

Returns:



70
71
72
# File 'lib/ronin/web/user_agents.rb', line 70

def self.chrome
  Chrome
end

.firefoxFirefox

Firefox User-Agent strings.

Examples:

user_agent = Ronin::Web::UserAgents.firefox.random
# => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16.0; rv:52.55.07) Gecko/20100101 Firefox/52.55.07" 

Returns:



98
99
100
# File 'lib/ronin/web/user_agents.rb', line 98

def self.firefox
  Firefox
end

.google_botGoogleBot

GoogleBot User-Agent strings.

Examples:

user_agent = Ronin::Web::UserAgents.google_bot.random
# => "GoogleBot/2.1 (+http://www.google.com/bot.html)"

Returns:



113
114
115
# File 'lib/ronin/web/user_agents.rb', line 113

def self.google_bot
  GoogleBot
end

.google_chromeChrome

Alias for chrome.

Returns:

See Also:



83
84
85
# File 'lib/ronin/web/user_agents.rb', line 83

def self.google_chrome
  Chrome
end

.random(&block) ⇒ String?

Returns a random Browser User-Agent string from one of the following:

Examples:

Ronin::Web::UserAgents.random
# => "Mozilla/5.0 (X11; Fedora; Linux i686; en-IE; rv:123.4) Gecko/20100101 Firefox/123.4"

Returns:

  • (String, nil)

    A random User-Agent string from the category. Note, nil can be returned if the given block filter out all User Agents.



132
133
134
135
136
137
138
139
# File 'lib/ronin/web/user_agents.rb', line 132

def self.random(&block)
  method = [
    :chrome,
    :firefox,
  ].sample

  return send(method).random(&block)
end