Discuz教程网

动态程序防采集的新方法

[复制链接]
authicon dly 发表于 2010-11-6 18:06:14 | 显示全部楼层 |阅读模式
昨天在网上看到一个防采集软件,说采集只访问当前网页,不会访问网页的图片、JS等,今天突然想到,通过动态程序和Js访问分别记录访问者的IP,然后进行IP判断,由于采集过程不会访问JS,采集的时候只会查到用动态程序记录的IP,而不会有通过JS记录的IP,从而实现网页程序的防采集。防采集的原理非常简单,首先放一段动态语句,把访问者的IP加入到数据库的一个表里,然后在页面底部加入一个JS,JS直接访问动态页面,将访问者的IP加入到数据库的另外一个表里。再次访问的时候,从两个表里读IP数据,然后判断时间差,如果只在第一个表里找到,在第二个表里找不到,或者时间差超过10秒,则认为是采集。优点1.部署简单,只要是动态语言就能很容易的实现,无需借助服务器端程序2.杀伤力大,几乎能封杀所有的采集过程缺点1.第一个缺点还是杀伤力大,如果需要实际使用需要考虑一些特殊情况,以免误杀已经杀掉搜索爬虫2.只适用于动态网页,静态页面就没法用了流程写的比较乱,不过原理本身就不是很复杂,下面附上程序例子,懂ASP的应该很快就能看懂。1.建立数据库表1:Ip1,字段Ip1_Adderss(文本),Ip1_Time(日期/时间,默认值=Now())表2:Ip2,字段Ip2_Adderss(文本),Ip2_Time(日期/时间,默认值=Now())2.Index.asp(仅动态代码,全部代码请见测试程序中)
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
  2. <%
  3. Dim Conn,Rs,Sqlstr,Ip,IpTime,IpTime2,NewUser
  4. NewUser=0
  5. Set Conn = Server.CreateObject("Adodb.Connection")
  6. Set Rs=Server.Createobject("Adodb.RecordSet")
  7. ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("Data.mdb")
  8. Conn.Open ConnStr
  9. Ip=Request.ServerVariables("REMOTE_ADDR")
  10. Sqlstr="Select * From [Ip1] Where Ip1_Address='"&Ip&"' Order By Ip1_Id Desc"
  11. Rs.Open Sqlstr,Conn,1,3
  12. If Rs.Eof Then
  13. NewUser=1
  14. Application.Lock()
  15. Rs.AddNew()
  16. Rs("Ip1_Address")=Ip
  17. Rs.Update()
  18. Application.UnLock()
  19. Else
  20. IpTime=Rs("Ip1_Time")
  21. Application.Lock()
  22. Rs.AddNew()
  23. Rs("Ip1_Address")=Ip
  24. Rs.Update()
  25. Application.UnLock()
  26. End If
  27. Rs.Close
  28. If NewUser=0 Then
  29. Sqlstr="Select * From [Ip2] Where Ip2_Address='"&Ip&"' Order By Ip2_Id Desc"
  30. Rs.Open Sqlstr,Conn,1,3
  31. If Rs.Eof Then
  32. Rs.Close
  33. Response.Write("请勿采集!")
  34. Response.End()
  35. Else
  36. IpTime2=Rs("Ip2_Time")
  37. If DateDiff("s",IpTime2,IpTime)>10 Then
  38. Rs.Close
  39. Response.Write("请勿采集!")
  40. Response.End()
  41. End If
  42. End If
  43. Rs.Close
  44. End If
  45. %>
复制代码

3.Js.asp
  1. <%
  2. Dim Conn,Rs,Sqlstr,Ip
  3. Set Conn = Server.CreateObject("Adodb.Connection")
  4. Set Rs=Server.Createobject("Adodb.RecordSet")
  5. ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("Data.mdb")
  6. Conn.Open ConnStr
  7. Ip=Request.ServerVariables("REMOTE_ADDR")
  8. Sqlstr="Select * From [Ip2]"
  9. Rs.Open Sqlstr,Conn,1,3
  10. Application.Lock()
  11. Rs.AddNew()
  12. Rs("Ip2_Address")=Ip
  13. Rs.Update()
  14. Application.UnLock()
  15. Rs.Close
  16. %>
复制代码

4.Get.asp
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
  2. <%
  3. Response.Write(Server.HTMLEncode(GetHttpPage("http://localhost/Index.asp","GB2312")))
  4. '==============================
  5. '函 数 名:GetHttpPage
  6. '作 用:获取页面源代码函数
  7. '参 数:网址HttpUrl
  8. '==============================
  9. Function GetHttpPage(HttpUrl,Code)
  10. If IsNull(HttpUrl)=True Or HttpUrl="" Then
  11. GetHttpPage="A站点维护中!"
  12. Exit Function
  13. End If
  14. On Error Resume Next
  15. Dim Http
  16. Set Http=server.createobject("MSX"&"ML2.XML"&"HTTP")
  17. Http.open "GET",HttpUrl,False
  18. Http.Send()
  19. If Http.Readystate<>4 then
  20. Set Http=Nothing
  21. GetHttpPage="B站点维护中!"
  22. Exit function
  23. End if
  24. GetHttpPage=BytesToBSTR(Http.responseBody,Code)
  25. Set Http=Nothing
  26. If Err.number<>0 then
  27. Err.Clear
  28. GetHttpPage="C站点维护中!"
  29. Exit function
  30. End If
  31. End Function
  32. '==============================
  33. '函 数 名:BytesToBstr
  34. '作 用:转换编码函数
  35. '参 数:字符串Body,编码Cset
  36. '==============================
  37. Function BytesToBstr(Body,Cset)
  38. Dim Objstream
  39. Set Objstream = Server.CreateObject("ado"&"d"&"b.st"&"re"&"am")
  40. Objstream.Type = 1
  41. Objstream.Mode =3
  42. Objstream.Open
  43. Objstream.Write body
  44. Objstream.Position = 0
  45. Objstream.Type = 2
  46. Objstream.Charset = Cset
  47. BytesToBstr = Objstream.ReadText
  48. Objstream.Close
  49. set Objstream = nothing
  50. End Function
  51. %>
复制代码

本文由方卡在线(http://www.fangka.net/)原创,转载请注明出处。如有雷同,纯属巧合!
程序例子(ASP+ACCESS)(测试程序下载




上一篇:asp的日期转换星座函数
下一篇:asp无限级分类加js收缩伸展功能代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-3 05:44

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表