📄 browsersniffertool.java
字号:
public boolean getWin3x() { return test("win16") || test("windows 3") || test("windows 16-bit"); } public boolean getWin31() { return test("win16") || test("windows 3.1") || test("windows 16-bit"); } public boolean getWin95() { return test("win95") || test("windows 95"); } public boolean getWin98() { return test("win98") || test("windows 98"); } public boolean getWinnt() { return test("winnt") || test("windows nt") || test("nt4") || test("nt3"); } public boolean getWin2k() { return test("nt 5.0") || test("nt5"); } public boolean getWinxp() { return test("nt 5.1"); } public boolean getDotnet() { return test(".net clr"); } public boolean getWinme() { return test("win 9x 4.90"); } public boolean getWin32() { return getWin95() || getWin98() || getWinnt() || getWin2k() || getWinxp() || getWinme() || test("win32"); } public boolean getWindows() { return getWin16() || getWin31() || getWin95() || getWin98() || getWinnt() || getWin32() || getWin2k() || getWinme() || test("win"); } public boolean getMac() { return test("macintosh") || test("mac_"); } public boolean getMacosx() { return test("macintosh") || test("mac os x"); } public boolean getMac68k() { return getMac() && (test("68k") || test("68000")); } public boolean getMacppc() { return getMac() && (test("ppc") || test("powerpc")); } public boolean getAmiga() { return test("amiga"); } public boolean getEmacs() { return test("emacs"); } public boolean getOs2() { return test("os/2"); } public boolean getSun() { return test("sun"); } public boolean getSun4() { return test("sunos 4"); } public boolean getSun5() { return test("sunos 5"); } public boolean getSuni86() { return getSun() && test("i86"); } public boolean getIrix() { return test("irix"); } public boolean getIrix5() { return test("irix5"); } public boolean getIrix6() { return test("irix6"); } public boolean getHpux() { return test("hp-ux"); } public boolean getHpux9() { return getHpux() && test("09."); } public boolean getHpux10() { return getHpux() && test("10."); } public boolean getAix() { return test("aix"); } public boolean getAix1() { return test("aix 1"); } public boolean getAix2() { return test("aix 2"); } public boolean getAix3() { return test("aix 3"); } public boolean getAix4() { return test("aix 4"); } public boolean getLinux() { return test("linux"); } public boolean getSco() { return test("sco") || test("unix_sv"); } public boolean getUnixware() { return test("unix_system_v"); } public boolean getMpras() { return test("ncr"); } public boolean getReliant() { return test("reliantunix"); } public boolean getDec() { return test("dec") || test("osf1") || test("delalpha") || test("alphaserver") || test("ultrix") || test("alphastation"); } public boolean getSinix() { return test("sinix"); } public boolean getFreebsd() { return test("freebsd"); } public boolean getBsd() { return test("bsd"); } public boolean getX11() { return test("x11"); } public boolean getUnix() { return getX11() || getSun() || getIrix() || getHpux() || getSco() || getUnixware() || getMpras() || getReliant() || getDec() || getLinux() || getBsd() || test("unix"); } public boolean getVMS() { return test("vax") || test("openvms"); } /* Features */ /* Since support of those features is often partial, the sniffer returns true when a consequent subset is supported. */ public boolean getCss() { return (getIe() && getMajorVersion() >= 4) || (getNetscape() && getMajorVersion() >= 4) || getGecko() || getKonqueror() || (getOpera() && getMajorVersion() >= 3) || getSafari() || getLinks(); } public boolean getCss1() { return getCss(); } public boolean getCss2() { return getIe() && (getMac() && getMajorVersion() >= 5) || (getWin32() && getMajorVersion() >= 6) || getGecko() || // && version >= ? (getOpera() && getMajorVersion() >= 4) || (getSafari() && getMajorVersion() >= 2) || (getKonqueror() && getMajorVersion() >= 2); } public boolean getDom0() { return (getIe() && getMajorVersion() >= 3) || (getNetscape() && getMajorVersion() >= 2) || (getOpera() && getMajorVersion() >= 3) || getGecko() || getSafari() || getKonqueror(); } public boolean getDom1() { return (getIe() && getMajorVersion() >= 5) || getGecko() || (getSafari() && getMajorVersion() >= 2) || (getOpera() && getMajorVersion() >= 4) || (getKonqueror() && getMajorVersion() >= 2); } public boolean getDom2() { return (getIe() && getMajorVersion() >= 6) || (getMozilla() && getMajorVersion() >= 5.0) || (getOpera() && getMajorVersion() >= 7) || getFirefox(); } public boolean getJavascript() { return getDom0(); // good approximation } /* Helpers */ private boolean test(String key) { return userAgent.indexOf(key) != -1; } private void parseVersion() { try { if(version != null) { return; /* parsing of version already done */ } /* generic versionning */ Matcher v = Pattern.compile( "/" /* Version starts with a slash */ + "([A-Za-z]*" /* Eat any letters before the major version */ + "( [\\d]* )" /* Major version number is every digit before the first dot */ + "\\." /* The first dot */ + "( [\\d]* )" /* Minor version number is every digit after the first dot */ + "[^\\s]*)" /* Throw away the remaining */ , Pattern.COMMENTS).matcher(userAgent); if(v.find()) { version = v.group(1); try { majorVersion = Integer.parseInt(v.group(2)); String minor = v.group(3); if(minor.startsWith("0"))minorVersion = 0; else minorVersion = Integer.parseInt(minor); } catch(NumberFormatException nfe) {} } /* Firefox versionning */ if(test("firefox")) { Matcher fx = Pattern.compile( "/" + "(( [\\d]* )" /* Major version number is every digit before the first dot */ + "\\." /* The first dot */ + "( [\\d]* )" /* Minor version number is every digit after the first dot */ + "[^\\s]*)" /* Throw away the remaining */ , Pattern.COMMENTS) .matcher(userAgent); if(fx.find()) { version = fx.group(1); try { majorVersion = Integer.parseInt(fx.group(2)); String minor = fx.group(3); if(minor.startsWith("0"))minorVersion = 0; else minorVersion = Integer.parseInt(minor); } catch(NumberFormatException nfe) {} } } /* IE versionning */ if(test("compatible")) { Matcher ie = Pattern.compile( "compatible;" + "\\s*" + "\\w*" /* Browser name */ + "[\\s|/]" + "([A-Za-z]*" /* Eat any letters before the major version */ + "( [\\d]* )" /* Major version number is every digit before first dot */ + "\\." /* The first dot */ + "( [\\d]* )" /* Minor version number is digits after first dot */ + "[^\\s]*)" /* Throw away remaining dots and digits */ , Pattern.COMMENTS) .matcher(userAgent); if(ie.find()) { version = ie.group(1); try { majorVersion = Integer.parseInt(ie.group(2)); String minor = ie.group(3); if(minor.startsWith("0"))minorVersion = 0; else minorVersion = Integer.parseInt(minor); } catch(NumberFormatException nfe) {} } } /* Safari versionning*/ if(getSafari()) { Matcher safari = Pattern.compile( "safari/" + "(( [\\d]* )" /* Major version number is every digit before first dot */ + "(?:" + "\\." /* The first dot */ + " [\\d]* )?)" /* Minor version number is digits after first dot */ , Pattern.COMMENTS) .matcher(userAgent); if(safari.find()) { version = safari.group(1); try { int sv = Integer.parseInt(safari.group(2)); majorVersion = sv / 100; minorVersion = sv % 100; } catch(NumberFormatException nfe) {} } } /* Gecko-powered Netscape (i.e. Mozilla) versions */ if(getGecko() && getNetscape() && test("netscape")) { Matcher netscape = Pattern.compile( "netscape/" + "(( [\\d]* )" /* Major version number is every digit before the first dot */ + "\\." /* The first dot */ + "( [\\d]* )" /* Minor version number is every digit after the first dot */ + "[^\\s]*)" /* Throw away the remaining */ , Pattern.COMMENTS) .matcher(userAgent); if(netscape.find()) { version = netscape.group(1); try { majorVersion = Integer.parseInt(netscape.group(2)); String minor = netscape.group(3); if(minor.startsWith("0"))minorVersion = 0; else minorVersion = Integer.parseInt(minor); } catch(NumberFormatException nfe) {} } } /* last try if version not found */ if(version == null) { Matcher mv = Pattern.compile( "[\\w]+/" + "( [\\d]+ );" /* Major version number is every digit before the first dot */ , Pattern.COMMENTS) .matcher(userAgent); if(mv.find()) { version = mv.group(1); try { majorVersion = Integer.parseInt(version); minorVersion = 0; } catch(NumberFormatException nfe) {} } } /* gecko engine version */ if(getGecko()) { Matcher g = Pattern.compile( "\\([^)]*rv:(([\\d]*)\\.([\\d]*).*?)\\)" ).matcher(userAgent); if(g.find()) { geckoVersion = g.group(1); try { geckoMajorVersion = Integer.parseInt(g.group(2)); String minor = g.group(3); if(minor.startsWith("0"))geckoMinorVersion = 0; else geckoMinorVersion = Integer.parseInt(minor); } catch(NumberFormatException nfe) {} } } } catch(PatternSyntaxException nfe) { // where should I log ?! } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -