使用asp代码突破163相册的防盗连
程序员文章站
2023-01-25 14:59:33
从网上来的代码,,稍微修改了一些地方,其实用的是cache类。。 保存代码为,比如pic.asp 使用:http://www.xxx.com/pic...
从网上来的代码,,稍微修改了一些地方,其实用的是cache类。。
保存代码为,比如pic.asp
使用:http://www.xxx.com/pic.asp?url=http://www.aaaa.com/log.gif
不光是163,其实就是很多防盗连的图片都可以这个实现。
<%
'盗链判断
'if instr(request.servervariables("http_referer"),"http://"&request.servervariables("server_name")&"") = 0 then
'response.write "非法链接"
'response.end
'end if
dim url, body, mycache
url = request.querystring("url")
set mycache = new cache
mycache.name = "picindex"&url
if mycache.valid then
body = mycache.value
else
body = getwebdata(url)
mycache.add body,dateadd("d",1,now)
end if
if err.number = 0 then
response.charset = "utf-8"
response.contenttype = "application/octet-stream"
response.binarywrite body
response.flush
else
wscript.echo err.description
end if
'取得数据
public function getwebdata(byval strurl)
dim curlpath
curlpath = mid(strurl,1,instr(8,strurl,"/"))
dim retrieval
set retrieval = server.createobject("microsoft.xmlhttp")
with retrieval
.open "get", strurl, false,"",""
.setrequestheader "referer", curlpath
.send
getwebdata =.responsebody
end with
set retrieval = nothing
end function
'cache类
class cache
private obj 'cache内容
private expiretime '过期时间
private expiretimename '过期时间application名
private cachename 'cache内容application名
private path 'url
private sub class_initialize()
path=request.servervariables("url")
path=left(path,instrrev(path,"/"))
end sub
private sub class_terminate()
end sub
public property get blempty
'是否为空
if isempty(obj) then
blempty=true
else
blempty=false
end if
end property
public property get valid
'是否可用(过期)
if isempty(obj) or not isdate(expiretime) then
valid=false
elseif cdate(expiretime)<now then
valid=false
else
valid=true
end if
end property
public property let name(str)
'设置cache名
cachename=str & path
obj=application(cachename)
expiretimename=str & "expires" & path
expiretime=application(expiretimename)
end property
public property let expires(tm)
'重设置过期时间
expiretime=tm
application.lock
application(expiretimename)=expiretime
application.unlock
end property
public sub add(var,expire)
'赋值
if isempty(var) or not isdate(expire) then
exit sub
end if
obj=var
expiretime=expire
application.lock
application(cachename)=obj
application(expiretimename)=expiretime
application.unlock
end sub
public property get value
'取值
if isempty(obj) or not isdate(expiretime) then
value=null
elseif cdate(expiretime)<now then
value=null
else
value=obj
end if
end property
public sub makeempty()
'释放application
application.lock
application(cachename)=empty
application(expiretimename)=empty
application.unlock
obj=empty
expiretime=empty
end sub
public function equal(var2)
'比较
if typename(obj)<>typename(var2) then
equal=false
elseif typename(obj)="object" then
if obj is var2 then
equal=true
else
equal=false
end if
elseif typename(obj)="variant()" then
if join(obj,"^")=join(var2,"^") then
equal=true
else
equal=false
end if
else
if obj=var2 then
equal=true
else
equal=false
end if
end if
end function
end class
%>
保存代码为,比如pic.asp
使用:http://www.xxx.com/pic.asp?url=http://www.aaaa.com/log.gif
不光是163,其实就是很多防盗连的图片都可以这个实现。
复制代码 代码如下:
<%
'盗链判断
'if instr(request.servervariables("http_referer"),"http://"&request.servervariables("server_name")&"") = 0 then
'response.write "非法链接"
'response.end
'end if
dim url, body, mycache
url = request.querystring("url")
set mycache = new cache
mycache.name = "picindex"&url
if mycache.valid then
body = mycache.value
else
body = getwebdata(url)
mycache.add body,dateadd("d",1,now)
end if
if err.number = 0 then
response.charset = "utf-8"
response.contenttype = "application/octet-stream"
response.binarywrite body
response.flush
else
wscript.echo err.description
end if
'取得数据
public function getwebdata(byval strurl)
dim curlpath
curlpath = mid(strurl,1,instr(8,strurl,"/"))
dim retrieval
set retrieval = server.createobject("microsoft.xmlhttp")
with retrieval
.open "get", strurl, false,"",""
.setrequestheader "referer", curlpath
.send
getwebdata =.responsebody
end with
set retrieval = nothing
end function
'cache类
class cache
private obj 'cache内容
private expiretime '过期时间
private expiretimename '过期时间application名
private cachename 'cache内容application名
private path 'url
private sub class_initialize()
path=request.servervariables("url")
path=left(path,instrrev(path,"/"))
end sub
private sub class_terminate()
end sub
public property get blempty
'是否为空
if isempty(obj) then
blempty=true
else
blempty=false
end if
end property
public property get valid
'是否可用(过期)
if isempty(obj) or not isdate(expiretime) then
valid=false
elseif cdate(expiretime)<now then
valid=false
else
valid=true
end if
end property
public property let name(str)
'设置cache名
cachename=str & path
obj=application(cachename)
expiretimename=str & "expires" & path
expiretime=application(expiretimename)
end property
public property let expires(tm)
'重设置过期时间
expiretime=tm
application.lock
application(expiretimename)=expiretime
application.unlock
end property
public sub add(var,expire)
'赋值
if isempty(var) or not isdate(expire) then
exit sub
end if
obj=var
expiretime=expire
application.lock
application(cachename)=obj
application(expiretimename)=expiretime
application.unlock
end sub
public property get value
'取值
if isempty(obj) or not isdate(expiretime) then
value=null
elseif cdate(expiretime)<now then
value=null
else
value=obj
end if
end property
public sub makeempty()
'释放application
application.lock
application(cachename)=empty
application(expiretimename)=empty
application.unlock
obj=empty
expiretime=empty
end sub
public function equal(var2)
'比较
if typename(obj)<>typename(var2) then
equal=false
elseif typename(obj)="object" then
if obj is var2 then
equal=true
else
equal=false
end if
elseif typename(obj)="variant()" then
if join(obj,"^")=join(var2,"^") then
equal=true
else
equal=false
end if
else
if obj=var2 then
equal=true
else
equal=false
end if
end if
end function
end class
%>
上一篇: 你认为河蟹怎么做好吃