<% 
On Error Resume Next 
'防御CC攻击模块
Dim IP0, UIP0, TimeOut, Interval, Anti_CC, CC, CC_Max 
TimeOut = 300 '超时时间(秒)  = 解封时间
Interval = 1  '最短刷新间隔(秒) 
CC_Max = 20   '临界值(次) 
IP0 = GetUserIp '客户端IP 
UIP0 = FiterIp(IP0)
Application.Lock 

For Each Anti_CC In Application.Contents 
	if instr(Application(Anti_CC),"ATCC") then
		CC = Split(Application(Anti_CC), "|") '分割为数组 
		If DateDiff("S", CC(2), Now)=>TimeOut or left(Anti_CC,1)<>"U" Then '超时则销毁变量 
			Application.Contents.Remove (Anti_CC) 
		End If 
	End If
Next

If instr(IP0,".") and isSpider=false then
	If IsEmpty(Application(UIP0)) Then '用户第一次访问 
		Application(UIP0) = "ATCC|0|" & Now & "|" & IP0
	Else 
		CC = Split(Application(UIP0), "|") 	'提取数据分割为数组 
		If Int(CC(1)) >= CC_Max Then 		'是否被封 
			Response.Write "你的访问频率太快，请不要快速刷新页面或者尝试CC攻击！5分钟后解锁！"
			Response.end
		Else 
			If DateDiff("s", CC(2), Now) <= Interval Then '判断访问间隔 
				CC(1) = Int(CC(1)) + 1 '临界值+1 
			Else 
				CC(1) = 0
				CC(2) = Now '刷新访问时间 
			End If 
			SaveToApp() '保存数据 
		End If 
	End If
End If 
Application.Unlock 
 	
function GetUserIp()
	dim strIPAddr,reg 
	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 
	strIPAddr = Trim(Mid(strIPAddr, 1, 30))
	strIPAddr = Replace(strIPAddr,Chr(0),"")
	strIPAddr = Replace(strIPAddr,"'","''")
	GetUserIp=strIPAddr
end function
 	
function FiterIp(t0)
	dim t1
	t1=replace(t0,".","")
	FiterIp="U"&t1
end function

function isSpider()
	isSpider=false
	dim agent:agent=request.servervariables("http_user_agent")
	if agent="" then exit function
	dim str01
	str01=split("Baidu|Google|archiver|ASPSeek|Yahoo|sohu|MSNBOT|360","|")
	dim i
	for i=0 to ubound(str01)
		if instr(lcase(agent),lcase(str01(i)))>0 then
			isSpider=true
			exit function
		end if
	next
end function

Function SaveToApp() '保存数据到内存 
	Application(UIP0) = "ATCC|" & CC(1) & "|" & CC(2) & "|" & IP0 
End Function 
%>