记录用户和搜索引擎蜘蛛爬行访问页面及IP的功能(ASP)
作者:飘逸online 日期:2008-11-19
把以下代码放到页面里即可
程序代码<%
'获取当前Url参数的函数
Private Function GetUrl()
Dim ScriptAddress, M_ItemUrl, M_item
ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME")) '取得当前地址
M_ItemUrl = ""
If (Request.QueryString <> "") Then
ScriptAddress = ScriptAddress & "?"
For Each M_item In Request.QueryString
If InStr(page,M_Item)=0 Then
M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&"")) & "&"
End If
Next
end if
GetUrl = ScriptAddress & M_ItemUrl
End Function
Private Function getIP()
'查询IP
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" or InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
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
'连接SQL数据库
Function conn_b()
on error resume next
Dim Conndb,Strconn
set Conndb=server.createobject("adodb.connection")
Strconn ="Provider=SQLOLEDB.1;Initial Catalog=数据库名称;Data Source=数据库IP;Uid=用户名;Pwd=密码;"
Conndb.open Strconn
set conn_b=Conndb
Set Rsb =Server.CreateObject("ADODB.RecordSet")
If Err Then
err.Clear
conn_b.close:set conn_b=nothing
Response.Write "对不起,连接超时。"
Response.End
End If
End Function
'记录到表ie521_getbot中(这个表,你自己建吧~)
sqlb="select * from ie521_getbot where 0=1"
rsb.open sqlb,conn_b,2,2
rsb.addnew
if getbot<>"" then rsb("bot")=getbot
rsb("ip")=getip
rsb("url")=geturl
rsb("showtime")=now
rsb.update
rsb.close
set rsb=nothing
%>
评论: 0 | 引用: 0 | 查看次数: -
发表评论
上一篇
下一篇

文章来自:
Tags: