欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp 判断是否为搜索引擎蜘蛛的代码

程序员文章站 2024-02-06 20:38:28
复制代码 代码如下: <% function getbot() '查询蜘蛛 dim s_agent getbot="" s_agent=req...

复制代码 代码如下:

<%
function getbot()
'查询蜘蛛
dim s_agent
getbot=""
s_agent=request.servervariables("http_user_agent") ‘关键判断语句
if instr(1,s_agent,"googlebot",1) >0 then
getbot="google"
end if
if instr(1,s_agent,"msnbot",1) >0 then
getbot="msn"
end if
if instr(1,s_agent,"slurp",1) >0 then
getbot="yahoo"
end if
if instr(1,s_agent,"baiduspider",1) >0 then
getbot="baidu"
end if
if instr(1,s_agent,"sohu-search",1) >0 then
getbot="sohu"
end if
if instr(1,s_agent,"lycos",1) >0 then
getbot="lycos"
end if
if instr(1,s_agent,"robozilla",1) >0 then
getbot="robozilla"
end if
end function
if getbot="baidu" then
'给百度定制的内容
elseif getbot="google" then
'给google 定制的内容
end if
%>

下面是比较完整的代码需要的朋友也可以参考下。里面还包括了一些客户端信息。
复制代码 代码如下:

class systeminfo_cls
public browser, version, platform, issearch, alexatoolbar
private sub class_initialize()
dim agent, tmpstr
issearch = false
if not isempty(session("systeminfo_cls")) then
tmpstr = split(session("systeminfo_cls"), "|||")
browser = tmpstr(0)
version = tmpstr(1)
platform = tmpstr(2)
alexatoolbar = tmpstr(4)
if tmpstr(3) = "1" then
issearch = true
end if
exit sub
end if
browser = "unknown"
version = "unknown"
platform = "unknown"
agent = request.servervariables("http_user_agent")
if instr(agent, "alexa toolbar") > 0 then
alexatoolbar = "yes"
else
alexatoolbar = "no"
end if
if left(agent, 7) = "mozilla" then '有此标识为浏览器
agent = split(agent, ";")
if instr(agent(1), "msie") > 0 then
browser = "internet explorer "
version = trim(left(replace(agent(1), "msie", ""), 6))
elseif instr(agent(4), "netscape") > 0 then
browser = "netscape "
tmpstr = split(agent(4), "/")
version = tmpstr(ubound(tmpstr))
elseif instr(agent(4), "rv:") > 0 then
browser = "mozilla "
tmpstr = split(agent(4), ":")
version = tmpstr(ubound(tmpstr))
if instr(version, ")") > 0 then
tmpstr = split(version, ")")
version = tmpstr(0)
end if
end if
if instr(agent(2), "nt 5.2") > 0 then
platform = "windows 2003"
elseif instr(agent(2), "windows ce") > 0 then
platform = "windows ce"
elseif instr(agent(2), "nt 5.1") > 0 then
platform = "windows xp"
elseif instr(agent(2), "nt 4.0") > 0 then
platform = "windows nt"
elseif instr(agent(2), "nt 5.0") > 0 then
platform = "windows 2000"
elseif instr(agent(2), "nt") > 0 then
platform = "windows nt"
elseif instr(agent(2), "9x") > 0 then
platform = "windows me"
elseif instr(agent(2), "98") > 0 then
platform = "windows 98"
elseif instr(agent(2), "95") > 0 then
platform = "windows 95"
elseif instr(agent(2), "win32") > 0 then
platform = "win32"
elseif instr(agent(2), "linux") > 0 then
platform = "linux"
elseif instr(agent(2), "sunos") > 0 then
platform = "sunos"
elseif instr(agent(2), "mac") > 0 then
platform = "mac"
elseif ubound(agent) > 2 then
if instr(agent(3), "nt 5.1") > 0 then
platform = "windows xp"
end if
if instr(agent(3), "linux") > 0 then
platform = "linux"
end if
end if
if instr(agent(2), "windows") > 0 and platform = "unknown" then
platform = "windows"
end if
elseif left(agent, 5) = "opera" then '有此标识为浏览器
agent = split(agent, "/")
browser = "mozilla "
tmpstr = split(agent(1), " ")
version = tmpstr(0)
if instr(agent(1), "nt 5.2") > 0 then
platform = "windows 2003"
elseif instr(agent(1), "windows ce") > 0 then
platform = "windows ce"
elseif instr(agent(1), "nt 5.1") > 0 then
platform = "windows xp"
elseif instr(agent(1), "nt 4.0") > 0 then
platform = "windows nt"
elseif instr(agent(1), "nt 5.0") > 0 then
platform = "windows 2000"
elseif instr(agent(1), "nt") > 0 then
platform = "windows nt"
elseif instr(agent(1), "9x") > 0 then
platform = "windows me"
elseif instr(agent(1), "98") > 0 then
platform = "windows 98"
elseif instr(agent(1), "95") > 0 then
platform = "windows 95"
elseif instr(agent(1), "win32") > 0 then
platform = "win32"
elseif instr(agent(1), "linux") > 0 then
platform = "linux"
elseif instr(agent(1), "sunos") > 0 then
platform = "sunos"
elseif instr(agent(1), "mac") > 0 then
platform = "mac"
elseif ubound(agent) > 2 then
if instr(agent(3), "nt 5.1") > 0 then
platform = "windows xp"
end if
if instr(agent(3), "linux") > 0 then
platform = "linux"
end if
end if
else
'识别搜索引擎
dim botlist, i
botlist = "google,isaac,webdup,surveybot,baiduspider,ia_archiver,p.arthur,fast-webcrawler,java,microsoft-atl-native,turnitinbot,webgather,sleipnir"
botlist = split(botlist, ",")
for i = 0 to ubound(botlist)
if instr(agent, botlist(i)) > 0 then
platform = botlist(i) & "搜索器"
issearch = true
exit for
end if
next
end if
if issearch then
browser = ""
version = ""
session("systeminfo_cls") = browser & "|||" & version & "|||" & platform & "|||1|||" & alexatoolbar
else
session("systeminfo_cls") = browser & "|||" & version & "|||" & platform & "|||0|||" & alexatoolbar
end if
end sub
end class