Chinaunix首页 | 论坛 | 博客
  • 博客访问: 899815
  • 博文数量: 322
  • 博客积分: 6688
  • 博客等级: 准将
  • 技术积分: 3626
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-19 11:26
文章分类

全部博文(322)

文章存档

2013年(5)

2012年(66)

2011年(87)

2010年(164)

分类: 系统运维

2011-06-27 16:56:06

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
Insert title here
<%
String userAgent = request.getHeader("User-Agent");
String target = "";
out.println("userAgent=" + userAgent);
target = getMobileOSFromUserAgent(userAgent) +  "-" + getPCOSFromUserAgent(userAgent) +"-" + getBroswerTypeFromUserAgent(userAgent);
out.println("target=" + target);
%>
<%!
// Check Mobile OS
private String getMobileOSFromUserAgent(String userAgent){
String type="";
if(userAgent.indexOf("Windows CE",1)>0){
type = "Windows CE|手机系统";
}else if(userAgent.indexOf("iPhone",1) > 0){
type="iPhone|手机系统";
}else if(userAgent.indexOf("BlackBerry",1) > 0){
type="BlackBerry|手机系统";
}else if(userAgent.indexOf("Series60",1) > 0 && userAgent.indexOf("NOKIA",1) > 0){
type="Nokia S60|手机系统";
}else if(userAgent.indexOf("NOKIA",1) > 0){
type="NOKIA|手机系统";
}else if(userAgent.indexOf("SymbianOS",1) > 0 || userAgent.indexOf("Series",1) > 0){
type="SymbianOS|手机系统";
}else if(userAgent.indexOf("SonyEricsson",1) > 0){
type="SonyEricsson|手机系统";
}
return type;
}
//Check PC OS             
private String getPCOSFromUserAgent(String userAgent){
String type = "";
if(userAgent.indexOf("Windows NT 6.1",1)>0){
type = "Windows 7|电脑系统";
}else if(userAgent.indexOf("Windows NT 6.0",1) > 0){
type="Windows Vista|电脑系统";
}else if(userAgent.indexOf("Windows NT 5.2",1) > 0){
type="Windows 2003|电脑系统";
}else if(userAgent.indexOf("Windows NT 5.1",1) > 0){
type="Windows XP|电脑系统";
}else if(userAgent.indexOf("Windows NT 5.0",1) > 0){
type="Windows 2000|电脑系统";
}else if(userAgent.indexOf("Windows NT",1) > 0){
type="Windows NT|电脑系统";
}else if(userAgent.indexOf("Windows 9",1) > 0 || userAgent.indexOf("Windows 4",1) > 0){
type="Windows 9x|电脑系统";
}else if(userAgent.indexOf("Unix",1) > 0 || userAgent.indexOf("SunOS",1) > 0 || userAgent.indexOf("BSD",1) > 0){
type="Unix|电脑系统";
}else if(userAgent.indexOf("RedHat",1) > 0){
type="Linux RedHat|电脑系统";
}else if(userAgent.indexOf("Ubuntu",1) > 0){
type="Linux Ubuntu|电脑系统";
}else if(userAgent.indexOf("Linux",1) > 0){
type="Linux|电脑系统";
}else if(userAgent.indexOf("Mac",1) > 0){
type="Mac|电脑系统";
}
return type;
}
// check broswer
private String getBroswerTypeFromUserAgent(String userAgent){
String type = "";
//Use the Kernel of IE:MAXTHON,GreenBrowser TencentTraveler MyIE NetCaptor
if(userAgent.indexOf("GreenBrowser",1) > 0){
type+="GreenBrowser|浏览器";
}else if(userAgent.indexOf("NetCaptor",1) > 0){
type+="NetCaptor|浏览器";
}else if(userAgent.indexOf("TencentTraveler",1) > 0){
type+="TencentTraveler|浏览器";
}else if(userAgent.indexOf("TheWorld",1) > 0){
type+="TheWorld|浏览器";
}else if(userAgent.indexOf("MAXTHON",1) > 0){
type+="Maxthon|浏览器";
}else if(userAgent.indexOf("MyIE",1) > 0){
type+="MyIE|浏览器";
}
//IE
else if(userAgent.indexOf("MSIE 8",1) > 0){
type+="IE 8|浏览器";
}else if(userAgent.indexOf("MSIE 7",1) > 0){
type+="MSIE 7|浏览器";
}else if(userAgent.indexOf("MSIE 6",1) > 0){
type+="MSIE 6|浏览器";
}else if(userAgent.indexOf("MSIE 5",1) > 0){
type+="IE 5|浏览器";
}else if(userAgent.indexOf("MSIE 4",1) > 0){
type+="MSIE 4|浏览器";
}else if(userAgent.indexOf("MSIE 3",1) > 0){
type+="MSIE 3|浏览器";
}
//None IE
else if(userAgent.indexOf("Netscape",1) > 0){
type+="Netscape|浏览器";
}else if(userAgent.indexOf("Chrome",1) > 0){
type+="Chrome|浏览器";
}else if(userAgent.indexOf("Firefox",1) > 0){
type+="Firefox|浏览器";
}else if(userAgent.indexOf("Safari",1) > 0){
type+="vs|浏览器";
}else if(userAgent.indexOf("Opera Mini",1) > 0){
type+="Opera Mini|浏览器";
}else if(userAgent.indexOf("Opera",1) > 0){
type+="Opera|浏览器";
}else if(userAgent.indexOf("R4EA",1) > 0){
type+="R4EA|浏览器";
}else if(userAgent.indexOf("UP",1) > 0){
type="UP|浏览器";
}else if(userAgent.indexOf("UCWEB",1) > 0){
type+="UCWEB|浏览器";
}
return type;
}
%>



<%dim UserAgent1

UserAgent1=""&trim(Request.ServerVariables("HTTP_USER_AGENT"))&""
if UserAgent1="" then
   UserAgent1="UserAgent Unknown"
else
   UserAgent1=""&UserAgent1&""
end if
Function getOS(UserAgent)
'下面三种判定,写在一起
    if UserAgent="UserAgent Unknown" then :vOs="UserAgent isNull OS Unknown|Other":getOS=vOS:exit Function:end if
    dim vOS
'-------先判定手机系统
if instr(1,UserAgent,"Windows CE",1)>0 then
   vOs="Windows CE|手机系统"
elseif instr(1,UserAgent,"iPhone",1)>0 then
   vOs="iPhone|手机系统"
elseif instr(1,UserAgent,"BlackBerry",1)>0 then
   vOs="BlackBerry|手机系统"
elseif instr(1,UserAgent,"Series60",1)>0 and instr(1,UserAgent,"NOKIA",1)>0 then
   vOs="Nokia S60|手机系统"
elseif instr(1,UserAgent,"NOKIA",1)>0 then
   vOs="Nokia|手机系统"
elseif instr(1,UserAgent,"SymbianOS",1)>0 or instr(1,UserAgent,"Series",1)>0 then
   vOs="SymbianOS|手机系统"
elseif instr(1,UserAgent,"SonyEricsson",1)>0 then
   vOs="SonyEricsson|手机系统"
elseif instr(1,UserAgent,"LG",1)>0 then
   vOs="LG手机|手机系统"
elseif instr(1,UserAgent,"MOT",1)>0 or instr(1,UserAgent,"Motorola",1)>0 then
   vOs="MOTO手机|手机系统"
elseif instr(1,UserAgent,"SEC",1)>0 or instr(1,UserAgent,"SAMSUNG",1)>0 then
   vOs="三星手机|手机系统"
elseif instr(1,UserAgent,"ZTE")>0 then
   vOs="中兴手机|手机系统"
elseif instr(1,UserAgent,"DX",1)>0 or instr(1,UserAgent,"DAXIAN",1)>0 then
   vOs="大显手机|手机系统"
elseif instr(1,UserAgent,"TELSON",1)>0 then
   vOs="泰信[代工]手机|手机系统"
elseif instr(1,UserAgent,"Dopod",1)>0 then
   vOs="多普达手机|手机系统"
elseif instr(1,UserAgent,"PHILIPS",1)>0 then
   vOs="PHILIPS手机|手机系统"
elseif instr(1,UserAgent,"Haier",1)>0 then
   vOs="海尔手机|手机系统"
elseif instr(1,UserAgent,"LENOVO",1)>0 then
   vOs="联想手机|手机系统"
elseif instr(1,UserAgent,"CECT",1)>0 then
   vOs="CECT手机|手机系统"
elseif instr(1,UserAgent,"NEC",1)>0 then
   vOs="NEC手机|手机系统"
elseif instr(1,UserAgent,"Bird",1)>0 then
   vOs="波导手机|手机系统"
elseif instr(1,UserAgent,"DBTEL",1)>0 then
   vOs="迪比特手机|手机系统"
elseif instr(1,UserAgent,"TCL",1)>0 then
   vOs="TCL手机|手机系统"
elseif instr(1,UserAgent,"oppo",1)>0 then
   vOs="Oppo手机|手机系统"
elseif instr(1,UserAgent,"AMOI",1)>0 then
   vOs="夏新手机|手机系统"
elseif instr(1,UserAgent,"Alcatel",1)>0 then
   vOs="阿尔卡特手机|手机系统"
elseif instr(1,UserAgent,"Ericsson",1)>0 then
   vOs="爱立信手机|手机系统"
elseif instr(1,UserAgent,"BenQ",1)>0 then
   vOs="明基手机|手机系统"
elseif instr(1,UserAgent,"KONKA",1)>0 then
   vOs="康佳手机|手机系统"
elseif instr(1,UserAgent,"ChangHong",1)>0 then
   vOs="长虹手机|手机系统"
elseif instr(1,UserAgent,"MALATA",1)>0 then
   vOs="万利达手机|手机系统"
elseif instr(1,UserAgent,"KTOUCH",1)>0 or instr(1,UserAgent,"TIANYU",1)>0 or instr(1,UserAgent,"K-TOUCH",1)>0 then
   vOs="天语手机|手机系统"
'---------------下面2个要在手机中最后判定,最普通的手机了MAUI-----------
elseif instr(1,UserAgent,"MAUI",1)>0 then
   vOs="MTK杂牌手机|手机系统"
elseif instr(1,UserAgent,"MIDP",1)>0 or instr(1,UserAgent,"JAVA",1)>0 or instr(1,UserAgent,"J2ME",1)>0 then
   vOs="Java移动设备|手机系统"
else
   vOs="Other|手机系统"
end if
if vOs<>"Other|手机系统" then:getOS=vOS:exit Function:end if

'---------再判定电脑系统
if instr(1,UserAgent,"Windows NT 6.1",1)>0 then
   vOS="Windows 7|电脑系统"
elseif instr(1,UserAgent,"Windows NT 6.0",1)>0 then
   vOS="Windows Vista|电脑系统"
elseif instr(1,UserAgent,"Windows NT 5.2",1)>0 then
   vOS="Windows 2003|电脑系统"
elseif instr(1,UserAgent,"Windows NT 5.1",1)>0 then
   vOs="Windows XP|电脑系统"
elseif instr(1,UserAgent,"Windows NT 5.0",1)>0 then
   vOS="Windows 2000|电脑系统"
elseif instr(1,UserAgent,"Windows NT",1)>0 then
   vOs="Windows NT|电脑系统"
   
'4.0 is win95 ,4.1 is win98 ,4.9 is win me
elseif instr(1,UserAgent,"Windows 9",1)>0 or instr(1,UserAgent,"Windows 4",1)>0 then
   vOs="Windows 9x|电脑系统"
elseif instr(1,UserAgent,"Unix",1)>0 or instr(1,UserAgent,"SunOS",1)>0 or instr(1,UserAgent,"BSD",1)>0 then
   vOs="Unix|电脑系统"
elseif instr(1,UserAgent,"RedHat",1)>0 then
   vOs="Linux RedHat|电脑系统"
elseif instr(1,UserAgent,"Ubuntu",1)>0 then
   vOs="Linux Ubuntu|电脑系统"
elseif instr(1,UserAgent,"Linux",1)>0 then
   vOs="Linux|电脑系统"
elseif instr(1,UserAgent,"Mac",1)>0 then
   vOs="Mac|电脑系统"
else
   vOs="Other|电脑系统"
end if
if vOs<>"Other|电脑系统" then:getOS=vOS:exit Function:end if
'以上判定电脑系统完完毕BlackBerry


'-------最后判定搜索蜘蛛
'蜘蛛spiderAlcatel
if instr(1,UserAgent,"Baiduspider",1)>0 then
   vOs="Baidu spider|搜索蜘蛛"
elseif instr(1,UserAgent,"Googlebot",1)>0 then
   vOs="Google bot|搜索蜘蛛"
elseif instr(1,UserAgent,"msnbot",1)>0 then
   vOs="Msn bot|搜索蜘蛛"
elseif instr(1,UserAgent,"Yahoo",1)>0 then
   vOs="Yahoo bot|搜索蜘蛛"
elseif instr(1,UserAgent,"Sogou",1)>0 then
   vOs="Sogou spider|搜索蜘蛛"
elseif instr(1,UserAgent,"YodaoBot",1)>0 then
   vOs="Yodao Bot|搜索蜘蛛"
elseif instr(1,UserAgent,"Sosospider",1)>0 then
   vOs="Soso spider|搜索蜘蛛"
else
   vOs="Other|搜索蜘蛛"
end if

getOS=vOS
if vOs="Other|搜索蜘蛛" then:vOs="Other|Other":getOS=vOS:exit Function:end if
    
end Function

Function getIE(UserAgent)
if UserAgent="UserAgent Unknown" then :vOs="UserAgent isNull Browser Unknown|Other":getIE=vOS:exit Function:end if
dim vOS

'先判定使用IE内核的浏览器MAXTHON,GreenBrowser TencentTraveler MyIE NetCaptor
if instr(1,UserAgent,"GreenBrowser",1)>0 then
   vOS="GreenBrowser|浏览器"
elseif instr(1,UserAgent,"NetCaptor",1)>0 then
   vOS="NetCaptor|浏览器"
elseif instr(1,UserAgent,"TencentTraveler",1)>0 then
   vOS="TencentTraveler|浏览器"
elseif instr(1,UserAgent,"TheWorld",1)>0 then
   vOS="TheWorld|浏览器"
elseif instr(1,UserAgent,"MAXTHON",1)>0 then
   vOS="Maxthon|浏览器"
elseif instr(1,UserAgent,"MyIE",1)>0 then
   vOS="MyIE|浏览器"
'用IE内核的浏览器的判定要在IE前进行
elseif instr(1,UserAgent,"MSIE 8",1)>0 then
   vOS="IE 8|浏览器"
elseif instr(1,UserAgent,"MSIE 7",1)>0 then
   vOS="IE 7|浏览器"
elseif instr(1,UserAgent,"MSIE 6",1)>0 then
   vOS="IE 6|浏览器"
elseif instr(1,UserAgent,"MSIE 5.5",1)>0 then
   vOS="IE 5.5|浏览器"
elseif instr(1,UserAgent,"MSIE 5",1)>0 then
   vOS="IE 5|浏览器"
elseif instr(1,UserAgent,"MSIE 4",1)>0 then
   vOS="IE 4|浏览器"
elseif instr(1,UserAgent,"MSIE 3",1)>0 then
   vOS="IE 3|浏览器"
   
'下面是非IE内核浏览器
elseif instr(1,UserAgent,"Netscape",1)>0 then
   vOS="Netscape|浏览器"
elseif instr(1,UserAgent,"Chrome",1)>0 then
   vOS="Chrome|浏览器"
elseif instr(1,UserAgent,"Firefox",1)>0 then
   vOS="Firefox|浏览器"
elseif instr(1,UserAgent,"Safari",1)>0 then
   vOS="Safari|浏览器"
elseif instr(1,UserAgent,"Opera Mini",1)>0 then
   vOS="Opera Mini|浏览器"
elseif instr(1,UserAgent,"Opera",1)>0 or instr(1,UserAgent,"Presto",1)>0 then
   vOS="Opera|浏览器"
elseif instr(1,UserAgent,"R4EA",1)>0 then
   vOS="R4EA|浏览器"
elseif instr(1,UserAgent,"UP",1)>0 then
   vOS="UP|浏览器"
elseif instr(1,UserAgent,"UCWEB",1)>0 then
   vOS="UCWEB|浏览器"
else
   vOS="Other|浏览器"
end if
    getIE=vOS
end Function

%>
阅读(807) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~