MCPcopy Create free account
hub / github.com/dreadl0ck/netcap / ParseUserAgent

Function ParseUserAgent

decoder/stream/software/software.go:260–323  ·  view source on GitHub ↗

ParseUserAgent processes a raw user agent string and returned a structured instance.

(ua string)

Source from the content-addressed store, hash-verified

258
259// ParseUserAgent processes a raw user agent string and returned a structured instance.
260func ParseUserAgent(ua string) *userAgent {
261
262 if parser == nil {
263 return nil
264 }
265
266 var (
267 uaClient = parser.Parse(ua)
268 full, product, vendor, version string
269 )
270
271 if uaClient.UserAgent != nil {
272 vendor = uaClient.UserAgent.Family
273 version = uaClient.UserAgent.Major
274 if uaClient.UserAgent.Minor != "" {
275 version += "." + uaClient.UserAgent.Minor
276 }
277 if uaClient.UserAgent.Patch != "" {
278 version += "." + uaClient.UserAgent.Patch
279 }
280 full += " " + uaClient.UserAgent.Family
281 full += " " + uaClient.UserAgent.Major
282 full += " " + uaClient.UserAgent.Minor
283 full += " " + uaClient.UserAgent.Patch
284
285 if vendor == "Other" {
286 vendor = ""
287 }
288 }
289 if uaClient.Os != nil {
290 full += " " + uaClient.Os.Family
291 full += " " + uaClient.Os.Major
292 full += " " + uaClient.Os.Minor
293 full += " " + uaClient.Os.Patch
294 full += " " + uaClient.Os.PatchMinor
295 }
296 if uaClient.Device != nil {
297 product = uaClient.Device.Family
298 full += " " + uaClient.Device.Family
299
300 if product == "Other" {
301 product = ""
302 }
303 }
304
305 // if vendor could not be identified, try to determine based on product name
306 if vendor == "" {
307 vendor = determineVendor(product)
308 }
309
310 osName := uaClient.Os.ToString()
311 if osName == "Other" {
312 osName = ""
313 }
314
315 return &userAgent{
316 Client: uaClient,
317 Product: product,

Callers 2

ParseFunction · 0.92
WhatSoftwareHTTPFunction · 0.85

Calls 1

determineVendorFunction · 0.85

Tested by

no test coverage detected