Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Operating System from User-Agent HTTP Header [closed]

People also ask

What does user agent HTTP header do?

The User-Agent request header is a characteristic string that lets servers and network peers identify the application, operating system, vendor, and/or version of the requesting user agent.

Is user agent part of HTTP header?

When your browser is connected to a website, a User-Agent field is included in the HTTP header. The data of the header field varies from browser to browser. This information is used to serve different websites to different web browsers and different operating systems.

Can user agent be spoofed?

The process is called user-agent spoofing. Yes, when a browser or any client sends a different user-agent HTTP header from what they are and fake it that is called spoofing.

How do I change the user agent in HTTP request?

To set a custom user agent, include an agent string in the HTTP header User-Agent. For the integration name, use a string that clearly and meaningfully identifies your integration. For the integration version, use a build ID, commit hash, or other identifier that is updated when you release new integration versions.


Here's a quick list... let me know if I missed one you are interested in.

http://www.geekpedia.com/code47_Detect-operating-system-from-user-agent-string.html:

// Match user agent string with operating systems
Windows 3.11 => Win16,
Windows 95 => (Windows 95)|(Win95)|(Windows_95),
Windows 98 => (Windows 98)|(Win98),
Windows 2000 => (Windows NT 5.0)|(Windows 2000),
Windows XP => (Windows NT 5.1)|(Windows XP),
Windows Server 2003 => (Windows NT 5.2),
Windows Vista => (Windows NT 6.0),
Windows 7 => (Windows NT 6.1),
Windows 8 => (Windows NT 6.2),
Windows 10 => (Windows NT 10.0),
Windows NT 4.0 => (Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT),
Windows ME => Windows ME,
Open BSD => OpenBSD,
Sun OS => SunOS,
Linux => (Linux)|(X11),
Mac OS => (Mac_PowerPC)|(Macintosh),
QNX => QNX,
BeOS => BeOS,
OS/2 => OS/2,
Search Bot=>(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)


What language are you developing in? That makes a huge difference in what is available to you if you want to do data-mining on the user agent string.

  • PHP has "browser.php" which parses the user agent into the OS, Browser, and Browser version:
    • http://www.geekpedia.com/code47_Detect-operating-system-from-user-agent-string.html (warning: Win7 is Windows NT 6.1 not Windows NT 7.0)
  • Javascript has the Navigator object which has lots of details about the user's system
    • https://developer.mozilla.org/en/window.navigator
  • .NET has the HttpBrowserCapabilities object which can be used to determine Win32 or Win16, as well as useful capabilities of the browser
    • http://msdn.microsoft.com/en-us/library/system.web.httprequest.browser(VS.80).aspx
  • Zytrax.com also has a good database of User Agents for various different browsers on different systems if you just want the raw user-agents
    • http://www.zytrax.com/tech/web/browser_ids.htm

Nescio's response provides a good list. The second link under PHP in my list also contains basically the same information which is simple enough that you should be able to translate it to any language.

Keep in mind that using the user agent for anything is rife with problems. Unless you're willing to dedicate a portion of your development time to monitoring user agents visiting your site and performing constant maintenance, you should try to avoid doing it entirely. No matter what your use-case is for needing to detect the OS, every OS in every platform can have dramatic changes in very short time-frames so it is important to be mindful of this and careful about how and why you do OS detection.

To elaborate on the risks: On the desktop, a new OS version can come out every 6 weeks (Chrome OS), 6 months (Ubuntu), 1 year (Mac OS), or 2-3 years (Windows). Then you also need to account for OSes released for phones, tablets, gaming consoles, clocks, etc which can have much more frequent release cycles and unpredictable changes in market share. Just look at how BlackBerry, Palm OS, Web OS, iOS, Android, Windows Mobile, and Windows Phone have changed market share in just the last few years to name a few.

Unless the operating system is a dependency of your site, like if you're creating a targeted "download" page for an app (which in itself can be rife with problems), it is almost always better to use feature detection, which will allow you to future-proof your development without having to constantly maintain browser or OS detection code.


It's worth keeping in mind that the user agent header can easily be faked. I wouldn't rely on it for anything important.


It's nearly always a bad idea to do UA sniffing. You can't rely on it at all.

If you want to sent the client a response specific to its environment you should perhaps distinguish differences from content-type or encoding. These are rock-solid specified.


The User Agent from the browser is not something I would rely on for anything, We all use it for statistics, but we know they're not 100% accurate.

I use firefox and regularly spoof IE for some sites that don't like it, my regular UA is:

Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) 
Gecko/2008101315 Ubuntu/8.10 (intrepid) Firefox/3.0.3 

I sometimes use a firefox extension to change it to:

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; MS-RTC LM 8; 
.NET CLR 2.0.50727; .NET CLR 1.1.4322)

when you are looking at it, you would need to parse the different parts, the OS is the third part of the semicolon-delimited values between brackets.