DEV Community

Trix Cyrus
Trix Cyrus

Posted on

Generating Random User Agents in Rust: Introducing `rand_agents` Library

Author: Trix Cyrus

[Try My],Waymap Pentesting tool
[Follow] TrixSec Github
[Join] TrixSec Telegram


Hey there, fellow developers!

I’ve just released a new Rust library called rand_agents that generates random, realistic User-Agent strings. User-Agent strings are an essential part of web scraping, penetration testing, or simply simulating browser behavior. This library aims to provide developers with a quick and easy way to generate these strings for testing purposes.

🚀 What is rand_agents?

rand_agents is a lightweight Rust library that allows you to generate random User-Agent strings, mimicking various browsers, operating systems, and devices. This is especially useful for:

  • Web scraping: Rotate User-Agent strings to avoid being blocked.
  • Penetration testing: Simulate different browser behaviors.
  • Development and testing: Mimic requests from different devices and browsers.

🛠️ How to Install rand_agents?

You can add rand_agents to your project by including it as a dependency in your Cargo.toml:

[dependencies]
rand_agents = "1.0.0"
Enter fullscreen mode Exit fullscreen mode

Once added, you can start using it in your project!

Alternatively, if you want to install it globally:

You can install the rand_agents binary directly by running the following command:

cargo install rand_agents
Enter fullscreen mode Exit fullscreen mode

After installation, you can simply run the binary to generate a random User-Agent string.

🔧 Usage

Here’s a basic example of how to use the rand_agents library in your project:

use rand_agents::user_agent;

fn main() {
    let agent = user_agent();
    println!("Random User Agent: {}", agent);
}
Enter fullscreen mode Exit fullscreen mode

Example Output:

Random User Agent: Opera/9.27 (Raspbian; Apple MacBook Pro) AppleWebKit/619.1.22 (KHTML, like Gecko) RockMelt/75.0.406 Safari/619.1.22
Enter fullscreen mode Exit fullscreen mode

⚙️ Features

  • Generates User-Agent strings that mimic a variety of browsers like Chrome, Firefox, Safari, Opera, and more.
  • Supports multiple operating systems such as Windows, Linux, macOS, Android, and iOS.
  • Includes different devices like smartphones, laptops, tablets, and even gaming consoles.
  • Randomly selects the webkit version to give a more varied output.

~Trixsec

no website in cookie, Please visit a website first,cookie:{"_clck":"1ba1grj%7C2%7Cfuj%7C0%7C1911","PHPSESSID":"b35r59dq1vkav6e11he03987d5","_ga_LXJJFJVFZ5":"GS1.1.1742974136.1.0.1742974136.0.0.0","_ga":"GA1.1.696468400.1742974136","sc_is_visitor_unique":"rx12738620.1742974136.39BEF3F2B35B4A798CED492962A1DFAD.1.1.1.1.1.1.1.1.1","_gh_sess":"fEbgZgU3GmZ49xkN6AghsL4cH2UDg6qmL5gAkMFz818JuFGZPctWtpMiAT4StlkJOQe6FLdlCxuVP9F6cla7aoV%2BxQAaC4Huuxv2k778k%2FuhBPNkJv5zzZKJlRbtSakJGK6c55BEQmO15JZYpN2Chy7%2FHKGrebRES1XPxruoz6pbCAzwns2tzYW2mCPIO7rYbuedaYussxyT%2FdYC4eHK1fGd5TkqZPGQKgRflDtBHFc%2FzIySdbDFU9OlKpI1iDE%2BLsffprtDeMNWXpacC%2BUVIg%3D%3D--KYtl2PEizMgvxaHn--gENQRYPizk8e1RcsaBwLUA%3D%3D","cpu_bucket":"xlg","preferred_color_mode":"light","tz":"UTC","ahoy_visit":"48f9316b-b801-472e-b59f-bf42a6e61279","ahoy_visitor":"ef5879d5-f79e-4501-a10e-eeec8d6b93d2"}, website: undefined

Top comments (1)

Collapse
 
pullreview profile image
Pull Review with Scott Beeker

Thanks so much for the awesome share!

no website in cookie, Please visit a website first,cookie:{"_clck":"1ba1grj%7C2%7Cfuj%7C0%7C1911","PHPSESSID":"b35r59dq1vkav6e11he03987d5","_ga_LXJJFJVFZ5":"GS1.1.1742974136.1.0.1742974136.0.0.0","_ga":"GA1.1.696468400.1742974136","sc_is_visitor_unique":"rx12738620.1742974136.39BEF3F2B35B4A798CED492962A1DFAD.1.1.1.1.1.1.1.1.1","_gh_sess":"fEbgZgU3GmZ49xkN6AghsL4cH2UDg6qmL5gAkMFz818JuFGZPctWtpMiAT4StlkJOQe6FLdlCxuVP9F6cla7aoV%2BxQAaC4Huuxv2k778k%2FuhBPNkJv5zzZKJlRbtSakJGK6c55BEQmO15JZYpN2Chy7%2FHKGrebRES1XPxruoz6pbCAzwns2tzYW2mCPIO7rYbuedaYussxyT%2FdYC4eHK1fGd5TkqZPGQKgRflDtBHFc%2FzIySdbDFU9OlKpI1iDE%2BLsffprtDeMNWXpacC%2BUVIg%3D%3D--KYtl2PEizMgvxaHn--gENQRYPizk8e1RcsaBwLUA%3D%3D","cpu_bucket":"xlg","preferred_color_mode":"light","tz":"UTC","ahoy_visit":"48f9316b-b801-472e-b59f-bf42a6e61279","ahoy_visitor":"ef5879d5-f79e-4501-a10e-eeec8d6b93d2"}, website: undefined
no website in cookie, Please visit a website first,cookie:{"_clck":"1ba1grj%7C2%7Cfuj%7C0%7C1911","PHPSESSID":"b35r59dq1vkav6e11he03987d5","_ga_LXJJFJVFZ5":"GS1.1.1742974136.1.0.1742974136.0.0.0","_ga":"GA1.1.696468400.1742974136","sc_is_visitor_unique":"rx12738620.1742974136.39BEF3F2B35B4A798CED492962A1DFAD.1.1.1.1.1.1.1.1.1","_gh_sess":"fEbgZgU3GmZ49xkN6AghsL4cH2UDg6qmL5gAkMFz818JuFGZPctWtpMiAT4StlkJOQe6FLdlCxuVP9F6cla7aoV%2BxQAaC4Huuxv2k778k%2FuhBPNkJv5zzZKJlRbtSakJGK6c55BEQmO15JZYpN2Chy7%2FHKGrebRES1XPxruoz6pbCAzwns2tzYW2mCPIO7rYbuedaYussxyT%2FdYC4eHK1fGd5TkqZPGQKgRflDtBHFc%2FzIySdbDFU9OlKpI1iDE%2BLsffprtDeMNWXpacC%2BUVIg%3D%3D--KYtl2PEizMgvxaHn--gENQRYPizk8e1RcsaBwLUA%3D%3D","cpu_bucket":"xlg","preferred_color_mode":"light","tz":"UTC","ahoy_visit":"48f9316b-b801-472e-b59f-bf42a6e61279","ahoy_visitor":"ef5879d5-f79e-4501-a10e-eeec8d6b93d2"}, website: undefined