Java Web get client operating system Information

Source: Internet
Author: User

 PackageCom.java.basic.pattern;ImportJava.util.regex.Matcher;ImportJava.util.regex.Pattern;/*** Get client operating System Information * Get to User-agent from the header of HTTP, then use regular expressions to determine which operating system * * Temporarily matches only win 7, WinXP, Win2003, Win2000, MAC, WinNT, Linux, mac68k, Win9x * *@paramuseragent request.getheader ("User-agent") return value * *@author  * */ Public classClientos {Private Static FinalString user_agent = "";  Public Static voidMain (string[] args) {String Clientos=Getclientos (user_agent); }         Public Staticstring Getclientos (String useragent) {string cos= "Unknow os"; Pattern P= Pattern.compile (". * (Windows NT 6\\.1). *"); Matcher m=P.matcher (useragent); if(M.find ()) {cos= "Windows7"; returnCos; } P= Pattern.compile (". * (Windows NT 5\\.1| Windows XP). * "); M=P.matcher (useragent); if(M.find ()) {cos= "WinXP"; returnCos; } P= Pattern.compile (". * (Windows NT 5\\.2). *"); M=P.matcher (useragent); if(M.find ()) {cos= "Win2003"; returnCos; } P= Pattern.compile (". * (win2000| Windows 2000| Windows NT 5\\.0). * "); M=P.matcher (useragent); if(M.find ()) {cos= "Win2000"; returnCos; } P= Pattern.compile (". * (mac|apple| MACOS8). * "); M=P.matcher (useragent); if(M.find ()) {cos= "MAC"; returnCos; } P= Pattern.compile (". * (winnt| WINDOWSNT). * "); M=P.matcher (useragent); if(M.find ()) {cos= "WinNT"; returnCos; } P= Pattern.compile (". *linux.*"); if(M.find ()) {cos= "Linux"; returnCos; } P= Pattern.compile (". *68k|68000.*"); M=P.matcher (useragent); if(M.find ()) {cos= "mac68k"; returnCos; } P= Pattern.compile (". * (9x 4.90| Win9 (5|8) | Windows 9 (5|8) |95/nt| win32|32bit). * "); M=P.matcher (useragent); if(M.find ()) {cos= "Win9x"; returnCos; }                returnCos; }            }
View Code

Java Web get client operating system Information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.