get Os from user agent - Java Network

Java examples for Network:User Agent

Description

get Os from user agent

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String userAgent = "java2s.com";
        System.out.println(getOs(userAgent));
    }/*from www.  j a  va  2 s  . c o m*/

    @Deprecated
    public static String getOs(String userAgent) {
        String os = "";
        if (userAgent.indexOf("Windows NT 6.3") != -1) {
            os = "Windows 8.1";
        } else if (userAgent.indexOf("Windows NT 6.2") != -1) {
            os = "Windows 8";
        } else if (userAgent.indexOf("Windows NT 6.1") != -1) {
            os = "Windows 7";
        } else if (userAgent.indexOf("Windows NT 6.0") != -1) {
            os = "Windows Vista";
        } else if (userAgent.indexOf("Windows NT 5.2") != -1) {
            os = "Windows Server 2003";
        } else if (userAgent.indexOf("Windows XP") != -1) {
            os = "Windows XP";
        } else if (userAgent.indexOf("Windows NT 5.1") != -1) {
            os = "Windows XP";
        } else if (userAgent.indexOf("Windows 9x 4.90") != -1) {
            os = "Windows ME";
        } else if (userAgent.indexOf("Windows ME") != -1) {
            os = "Windows ME";
        } else if (userAgent.indexOf("Windows NT 5.0") != -1) {
            os = "Windows 2000";
        } else if (userAgent.indexOf("Windows 2000") != -1) {
            os = "Windows 2000";
        } else if (userAgent.indexOf("Windows 98") != -1) {
            os = "Windows 98";
        } else if (userAgent.indexOf("Windows NT 4.0") != -1) {
            os = "Windows NT";
        } else if (userAgent.indexOf("Windows 95") != -1) {
            os = "Windows 95";
        } else if (userAgent.indexOf("Mac") != -1) {
            os = "Mac OS";
        } else if (userAgent.indexOf("PPC") != -1) {
            os = "Mac OS";
        } else if (userAgent.indexOf("Linux") != -1) {
            os = "Linux";
        } else if (userAgent.indexOf("SunOS") != -1) {
            os = "Solaris";
        } else {
            os = "N/A";
        }
        return os;
    }
}

Related Tutorials