ronin-web-user_agents
Description
Yet another User-Agent
string generator library.
Features
- Generates random but realistic
User-Agent
strings from known values. - Small and fast.
- Zero dependencies.
- 93% documentation coverage.
- 99% test coverage.
Examples
Random
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"
Build a specific Chrome User-Agent
for Android 10.0 string:
Ronin::Web::UserAgents.chrome.build(chrome_version: '100.0.4758.81', os: :
android, os_version: '10.0')
# => "Mozilla/5.0 (Linux; Android 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4758.81 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"
Build a specific Firefox User-Agent
string for Windows 10:
Ronin::Web::UserAgents.firefox.build(firefox_version: '95.0', os: :windows, os_version: 10)
# => "Mozilla/5.0 (Windows NT 10.0; rv:100.0.4758.81) Gecko/20100101 Firefox/95.0"
Get a random googlebot
User-Agent
string:
user_agent = Ronin::Web::UserAgents.google_bot.random
# => "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; GoogleBot/2.1; +http://www.google.com/bot.html) Chrome/94.0.4602.7 Safari/537.36"
Spoof net/http's User-Agent
string:
require 'net/https'
uri = URI("https://www.whatismybrowser.com/detect/what-is-my-user-agent")
headers = {'User-Agent' => Ronin::Web::UserAgents.chrome.random}
response = Net::HTTP.get(uri,headers)
Spoofing
Spoof open-uri's User-Agent
string:
require 'open-uri'
url = "https://www.whatismybrowser.com/detect/what-is-my-user-agent"
headers = {'User-Agent' => Ronin::Web::UserAgents.chrome.random}
temp_file = URI.open(url,headers)
Spoof mechanize's User-Agent
string:
require 'mechanize'
agent = Mechanize.new
agent.user_agent = Ronin::Web::UserAgents.chrome.random
page = agent.get("https://www.whatismybrowser.com/detect/what-is-my-user-agent")
Spoof rest-client's User-Agent
string:
require 'rest-client'
RestClient.get "https://www.whatismybrowser.com/detect/what-is-my-user-agent",
user_agent: Ronin::Web::UserAgents.chrome.random
Spoof curl
's User-Agent
string:
user_agent="$(ruby -r ronin/web/user_agents -e 'print Ronin::Web::UserAgents.chrome.random')"
curl --user-agent "$user_agent" https://www.whatismybrowser.com/detect/what-is-my-user-agent
Requirements
- Ruby >= 3.0.0
Install
$ gem install ronin-web-user_agents
Gemfile
gem 'ronin-web-user_agents', '~> 0.1'
gemspec
gem.add_dependency 'ronin-web-user_agents', '~> 0.1'
Development
- Fork It!
- Clone It!
cd ronin-web-user_agents/
bundle install
git checkout -b my_feature
- Code It!
bundle exec rake spec
git push origin my_feature
License
Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3@gmail.com)
ronin-web-user_agents is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
ronin-web-user_agents is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with ronin-web-user_agents. If not, see https://www.gnu.org/licenses/.