使用asp代码突破图片的防盗连
2018-09-06 11:58
  从网上来的代码,,稍微修改了一些地方,其实用的是cache类。。 
保存代码为,比如pic.asp 
使用:
不光是163,其实就是很多防盗连的图片都可以这个实现。 
<% 
盗链判断 
IfInstr(Request.ServerVariables(http_referer),
Response.Write非法链接 
Response.End 
EndIf 
Dimurl,body,myCache 
url=Request.QueryString(url) 
SetmyCache=newcache 
IfmyCache.validThen 
body=myCache.value 
Else 
body=GetWebData(url) 
myCache.addbody,dateadd(d,1,now) 
EndIf 
IfErr.Number=0Then 
Response.CharSet=UTF-8 
Response.BinaryWritebody 
Response.Flush 
Else 
Wscript.EchoErr.Description 
Endif 
取得数据 
PublicFunctionGetWebData(ByValstrUrl) 
Dimcurlpath 
curlpath=Mid(strUrl,1,Instr(8,strUrl,/)) 
DimRetrieval 
SetRetrieval=Server.CreateObject(Microsoft.XMLHTTP) 
WithRetrieval 
.OpenGet,strUrl,False,, 
.setRequestHeaderReferer,curlpath 
.Send 
GetWebData=.ResponseBody 
EndWith 
SetRetrieval=Nothing 
EndFunction 
cache类 
classCache 
privateobjcache内容 
privateexpireTime过期时间 
privateexpireTimeName过期时间application名 
privatecacheNamecache内容application名 
privatepathurl 
privatesubclass_initialize() 
path=request.servervariables(url) 
path=left(path,instrRev(path,/)) 
endsub 
privatesubclass_terminate() 
endsub 
publicpropertygetblEmpty 
是否为空 
ifisempty(obj)then 
blEmpty=true 
else 
blEmpty=false 
endif 
endproperty 
publicpropertygetvalid 
是否可用(过期) 
ifisempty(obj)ornotisDate(expireTime)then 
valid=false 
elseifCDate(expireTime)<nowthen 
valid=false 
else 
valid=true 
endif 
endproperty 
publicpropertyletname(str) 
设置cache名 
cacheName=str&path 
obj=application(cacheName) 
expireTimeName=str&expires&path 
expireTime=application(expireTimeName) 
endproperty 
publicpropertyletexpires(tm) 
重设置过期时间 
expireTime=tm 
application.lock 
application(expireTimeName)=expireTime 
application.unlock 
endproperty 
publicsubadd(var,expire) 
赋值 
ifisempty(var)ornotisDate(expire)then 
exitsub 
endif 
obj=var 
expireTime=expire 
application.lock 
application(cacheName)=obj 
application(expireTimeName)=expireTime 
application.unlock 
endsub 
publicpropertygetvalue 
取值 
ifisempty(obj)ornotisDate(expireTime)then 
value=null 
elseifCDate(expireTime)<nowthen 
value=null 
else 
value=obj 
endif 
endproperty 
publicsubmakeEmpty() 
释放application 
application.lock 
application(cacheName)=empty 
application(expireTimeName)=empty 
application.unlock 
obj=empty 
expireTime=empty 
endsub 
publicfunctionequal(var2) 
比较 
iftypename(obj)<>typename(var2)then 
equal=false 
elseiftypename(obj)=Objectthen 
ifobjisvar2then 
equal=true 
else 
equal=false 
endif 
elseiftypename(obj)=Variant()then 
ifjoin(obj,^)=join(var2,^)then 
equal=true 
else 
equal=false 
endif 
else 
ifobj=var2then 
equal=true 
else 
equal=false 
endif 
endif 
endfunction 
endclass 
%> 
下一篇:ASP网站防范黑客技巧