昨天在網(wǎng)上看到一個(gè)防采集軟件,說(shuō)采集只訪問(wèn)當(dāng)前網(wǎng)頁(yè),不會(huì)訪問(wèn)網(wǎng)頁(yè)的圖片、JS等,今天突然想到,通過(guò)動(dòng)態(tài)程序和Js訪問(wèn)分別記錄訪問(wèn)者的IP,然后進(jìn)行IP判斷,由于采集過(guò)程不會(huì)訪問(wèn)JS,采集的時(shí)候只會(huì)查到用動(dòng)態(tài)程序記錄的IP,而不會(huì)有通過(guò)JS記錄的IP,從而實(shí)現(xiàn)網(wǎng)頁(yè)程序的防采集。
防采集的原理非常簡(jiǎn)單,首先放一段動(dòng)態(tài)語(yǔ)句,把訪問(wèn)者的IP加入到數(shù)據(jù)庫(kù)的一個(gè)表里,然后在頁(yè)面底部加入一個(gè)JS,JS直接訪問(wèn)動(dòng)態(tài)頁(yè)面,將訪問(wèn)者的IP加入到數(shù)據(jù)庫(kù)的另外一個(gè)表里。再次訪問(wèn)的時(shí)候,從兩個(gè)表里讀IP數(shù)據(jù),然后判斷時(shí)間差,如果只在第一個(gè)表里找到,在第二個(gè)表里找不到,或者時(shí)間差超過(guò)10秒,則認(rèn)為是采集。
優(yōu)點(diǎn)
1.部署簡(jiǎn)單,只要是動(dòng)態(tài)語(yǔ)言就能很容易的實(shí)現(xiàn),無(wú)需借助服務(wù)器端程序
2.殺傷力大,幾乎能封殺所有的采集過(guò)程
缺點(diǎn)
1.第一個(gè)缺點(diǎn)還是殺傷力大,如果需要實(shí)際使用需要考慮一些特殊情況,以免誤殺已經(jīng)殺掉搜索爬蟲
2.只適用于動(dòng)態(tài)網(wǎng)頁(yè),靜態(tài)頁(yè)面就沒(méi)法用了
流程寫的比較亂,不過(guò)原理本身就不是很復(fù)雜,下面附上程序例子,懂ASP的應(yīng)該很快就能看懂。
程序例子(ASP+ACCESS)(測(cè)試程序下載):
1.建立數(shù)據(jù)庫(kù)
表1:Ip1,字段Ip1_Adderss(文本),Ip1_Time(日期/時(shí)間,默認(rèn)值=Now())
表2:Ip2,字段Ip2_Adderss(文本),Ip2_Time(日期/時(shí)間,默認(rèn)值=Now())
2.Index.asp(僅動(dòng)態(tài)代碼,全部代碼請(qǐng)見測(cè)試程序中)
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
Dim Conn,Rs,Sqlstr,Ip,IpTime,IpTime2,NewUser
NewUser=0
Set Conn = Server.CreateObject("Adodb.Connection")
Set Rs=Server.Createobject("Adodb.RecordSet")
ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("Data.mdb")
Conn.Open ConnStr
Ip=Request.ServerVariables("REMOTE_ADDR")
Sqlstr="Select * From [Ip1] Where Ip1_Address='"&Ip&"' Order By Ip1_Id Desc"
Rs.Open Sqlstr,Conn,1,3
If Rs.Eof Then
NewUser=1
Application.Lock()
Rs.AddNew()
Rs("Ip1_Address")=Ip
Rs.Update()
Application.UnLock()
Else
IpTime=Rs("Ip1_Time")
Application.Lock()
Rs.AddNew()
Rs("Ip1_Address")=Ip
Rs.Update()
Application.UnLock()
End If
Rs.Close
If NewUser=0 Then
Sqlstr="Select * From [Ip2] Where Ip2_Address='"&Ip&"' Order By Ip2_Id Desc"
Rs.Open Sqlstr,Conn,1,3
If Rs.Eof Then
Rs.Close
Response.Write("請(qǐng)勿采集!")
Response.End()
Else
IpTime2=Rs("Ip2_Time")
If DateDiff("s",IpTime2,IpTime)>10 Then
Rs.Close
Response.Write("請(qǐng)勿采集!")
Response.End()
End If
End If
Rs.Close
End If
%>
3.Js.asp
<%
Dim Conn,Rs,Sqlstr,Ip
Set Conn = Server.CreateObject("Adodb.Connection")
Set Rs=Server.Createobject("Adodb.RecordSet")
ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("Data.mdb")
Conn.Open ConnStr
Ip=Request.ServerVariables("REMOTE_ADDR")
Sqlstr="Select * From [Ip2]"
Rs.Open Sqlstr,Conn,1,3
Application.Lock()
Rs.AddNew()
Rs("Ip2_Address")=Ip
Rs.Update()
Application.UnLock()
Rs.Close
%>
4.Get.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
Response.Write(Server.HTMLEncode(GetHttpPage("http://localhost/Index.asp","GB2312")))
'==============================
'函 數(shù) 名:GetHttpPage
'作 用:獲取頁(yè)面源代碼函數(shù)
'參 數(shù):網(wǎng)址HttpUrl
'==============================
Function GetHttpPage(HttpUrl,Code)
If IsNull(HttpUrl)=True Or HttpUrl="" Then
GetHttpPage="A站點(diǎn)維護(hù)中!"
Exit Function
End If
On Error Resume Next
Dim Http
Set Http=server.createobject("MSX"&"ML2.XML"&"HTTP")
Http.open "GET",HttpUrl,False
Http.Send()
If Http.Readystate<>4 then
Set Http=Nothing
GetHttpPage="B站點(diǎn)維護(hù)中!"
Exit function
End if
GetHttpPage=BytesToBSTR(Http.responseBody,Code)
Set Http=Nothing
If Err.number<>0 then
Err.Clear
GetHttpPage="C站點(diǎn)維護(hù)中!"
Exit function
End If
End Function
'==============================
'函 數(shù) 名:BytesToBstr
'作 用:轉(zhuǎn)換編碼函數(shù)
'參 數(shù):字符串Body,編碼Cset
'==============================
Function BytesToBstr(Body,Cset)
Dim Objstream
Set Objstream = Server.CreateObject("ado"&"d"&"b.st"&"re"&"am")
Objstream.Type = 1
Objstream.Mode =3
Objstream.Open
Objstream.Write body
Objstream.Position = 0
Objstream.Type = 2
Objstream.Charset = Cset
BytesToBstr = Objstream.ReadText
Objstream.Close
set Objstream = nothing
End Function
%>
更多信息請(qǐng)查看IT技術(shù)專欄