根据User Agent来判定操作系统与浏览器类型

程序是ASP写的,由服务器来判定,可以判定多种操作系统(含手机系统,不过国产机的UserAgent很乱,无法非常准确的判定,我想与国产手机厂商不重视这个有关,也许他们根本就不知道这个东西)我以为这是比较全面的判定了.许多User Agent是本人亲自收集并用来判定的.

附判定程序,原创,转载请注明出处:参见效果: http://www.zawen.net/counter/os.asp?id=1

<%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

%>

你可能感兴趣的:(根据User Agent来判定操作系统与浏览器类型)