Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Get a random, popular, commonly-used user agent string. Random/fake/spoof user agents.
Table of Contents
This is just a simple python module to produce a random, commonly used user agents each time. It contains 11 lists for a total of 1,100 user agents. You can choose and combine lists depending on your needs.
Assumes you have python3 installed.
pip install getuseragent
from getuseragent import UserAgent
useragent = UserAgent()
theuseragent = useragent.Random()
print(theuseragent)
Example output:
Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148
Each of the following lists contains 100 commonly used user agents for that software/device/system.
# Firefox
useragent = UserAgent("firefox")
# Chrome
useragent = UserAgent("chrome")
# Safari
useragent = UserAgent("safari")
# Internet Explorer (IE)
useragent = UserAgent("ie")
# Edge
useragent = UserAgent("edge")
# iOS
useragent = UserAgent("ios")
# Android
useragent = UserAgent("android")
# Windows
useragent = UserAgent("windows")
# Mac
useragent = UserAgent("mac")
# Linux
useragent = UserAgent("linux")
Sets including multiple lists:
# Desktop (Windows + Mac + Linux)
useragent = UserAgent("desktop")
# Mobile (iOS + Android)
useragent = UserAgent("mobile")
# All (Everything except bots)
useragent = UserAgent()
# or
useragent = UserAgent("all")
Bots like web crawlers:
# Bots
useragent = UserAgent("bots")
You can combine lists and sets together. Use the + sign between list names. Duplicate lists will automatically be removed so there's only 1 of each list at most.
Examples:
# Chrome and Edge and iOS
useragent = UserAgent("chrome+edge+ios")
# Mobile + Firefox
useragent = UserAgent("mobile+firefox")
# All + Bots
useragent = UserAgent("all+bots")
# Print a random user agent based on your selection:
print(useragent.Random())
You can print a single random user agent like so:
# Initialise
useragent = UserAgent()
# Get one random user agent
ua = useragent.Random()
# Print user agent
print(ua)
You can limit the total amount of user agents in the list to save memory. The default is no limit, and each list has 100 commonly used user agents.
# Using 3 lists would make the total available user agents 300
useragent = UserAgent("chrome+firefox+ios")
# You can limit the total to, for example, 50:
# (List is randomised before truncating)
useragent = UserAgent("chrome+firefox+ios", total=50)
# You can limit individual lists
# This would give 10 firefox user agents + 10 safari user agents
# The total amount of user agents available would be 20
useragent = UserAgent("firefox+safari", limit=10)
# You can combine limit and total
# This would get 10 user agents for both android and ie, for 20 user agents
# The list would be randomised, then reduced to 15 total available user agents
useragent = UserAgent("android+ie", limit=10, total=15)
# Print a random user agent
print(useragent.Random())
You can enable the option to return your user agents ready to be used with the requests module.
# Example
import requests
from getuseragent import UserAgent
myuseragent = UserAgent("all", requestsPrefix=True).Random()
# Example Output:
# --
# {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0'}
page = requests.get("https://google.com", headers=myuseragent)
1. Added individual list limits, which can be used when using one or multiple lists.
For example, if you used:
UserAgent("firefox+ios", limit=5)
It would limit each list to 5 user agents, and two lists, bringing the total user agents 10.
2. Checks if user agent files exist.
3. Checks if user list empty in Random()
Fixed package errors, spelling mistakes
Initial release
FAQs
Get a random, popular, commonly-used user agent string. Random/fake/spoof user agents.
We found that getuseragent demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.