<% Dim soft_id Dim rs Dim strAbsFile Const BadIPGroup = "122.143.1.*|119.84.114.13|183.60.212.*|183.60.213.*|183.60.214.*" If IsForbidIP(BadIPGroup) = True Then Response.redirect "http://www.vcap.com.cn" Response.End() CloseDb() return End If soft_id = trim(request.QueryString("id")) if soft_id <> "" and isnumeric(soft_id) then set rs=conn.execute("select * from soft where soft_id = "&soft_id ) if not rs.eof and not rs.bof then call add_history(soft_id) strAbsFile = rs("soft_url") Response.redirect strAbsFile 'DownloadFile( rs("soft_url") ) else Response.redirect "404.html" end if else Response.redirect "404.html" End If CloseDb() %> <% function add_history(id) sql = "insert into down_history(soft_id,down_ip) values("&id&",'"&GetIP()&"')" conn.execute(sql) end function Function IsForbidIP(vBadIP) Dim counter, arrIPPart, arrBadIP, arrBadIPPart, i, j arrBadIP = Split(vBadIP, "|") arrIPPart = Split(GetIP(), ".") For i = 0 To UBound(arrBadIP) counter = 0 arrBadIPPart = Split(arrBadIP(i), ".") For j = 0 To UBound(arrIPPart) If(arrBadIPPart(j)) = "*" or Cstr(arrIPPart(j)) = Cstr(arrBadIPPart(j)) Then counter = counter + 1 End If Next If counter = 4 Then IsForbidIP = True Exit Function End If Next IsForbidIP = False End Function Function GetIP() Dim IP IP = Request.ServerVariables("HTTP_X_FORWARDED_FOR") If IP = "" Then IP = Request.ServerVariables("REMOTE_ADDR") GetIP = IP End Function Private Sub DownloadFile(file) '--declare variables Dim strAbsFile Dim strFileExtension Dim objFSO Dim objFile Dim objStream '-- set absolute file location strAbsFile = file 'Server.MapPath(file) '-- create FSO object to check if file exists and get properties Set objFSO = Server.CreateObject("Scripting.FileSystemObject") '-- check to see if the file exists If objFSO.FileExists(strAbsFile) Then Set objFile = objFSO.GetFile(strAbsFile) '-- first clear the response, and then set the appropriate headers Response.Clear '-- the filename you give it will be the one that is shown ' to the users by default when they save Response.AddHeader "Content-Disposition", "attachment; filename=" & objFile.Name Response.AddHeader "Content-Length", objFile.Size Response.ContentType = "application/octet-stream" Set objStream = Server.CreateObject("ADODB.Stream") objStream.Open '-- set as binary objStream.Type = 1 Response.CharSet = "UTF-8" '-- load into the stream the file objStream.LoadFromFile(strAbsFile) '-- send the stream in the response Response.BinaryWrite(objStream.Read) objStream.Close Set objStream = Nothing Set objFile = Nothing Else 'objFSO.FileExists(strAbsFile) Response.Clear Response.Write strAbsFile Response.Write("No such file exists.") End If Set objFSO = Nothing End Sub Function DownloadFile2(strFile) StrFileName=strFile Response.Buffer=True Response.Clear Set S=Server.CreateObJect("ADODB.Stream") S.Open S.Type=1 on Error Resume Next Set Fso=Server.CreateObJect("Scripting.FileSystemObJect") If Not Fso.FileExists(StrFileName) Then From_Url=Cstr(Request.ServerVariables("HTTP_REFERER")) Serv_Url=Cstr(Request.ServerVariables("SERVER_NAME")) If Mid(From_Url,8,len(Serv_Url)) <> Serv_Url Then Response.Write "该文件不存在或者已经删除." Response.End End If Response.Redirect Request.ServerVariables("HTTP_REFERER") Response.End End If FileExt=Mid(StrFileName,InStrRev(StrFileName, ".")+1) Select Case UCase(FileExt) Case "ASP", "ASA", "ASPX", "ASAX", "MDB", "PHP", "JSP", "SHTML", "HTML", "HTM", "TV", "DATA" From_Url=Cstr(Request.ServerVariables("HTTP_REFERER")) Serv_Url=Cstr(Request.ServerVariables("SERVER_NAME")) If Mid(From_Url,8,len(Serv_Url)) <> Serv_Url Then Response.Write "该文件不存在或者已经删除." Response.End End If Response.Redirect Request.ServerVariables("HTTP_REFERER") Response.End End Select Set F=Fso.GetFile(StrFileName) IntFilelength=F.Size S.LoadFromFile(StrFileName) If Err Then From_Url=Cstr(Request.ServerVariables("HTTP_REFERER")) Serv_Url=Cstr(Request.ServerVariables("SERVER_NAME")) If Mid(From_Url,8,len(Serv_Url)) <> Serv_Url Then Response.Write "该文件数据不完整或许已损坏." Response.End End If Response.Redirect Request.ServerVariables("HTTP_REFERER") Response.End End If Set Upload=Server.CreateObJect("Persits.Upload") If Upload Is Nothing Then Response.AddHeader "Content-Disposition","attachment; Filename="&F.Name Response.AddHeader "Content-Length",IntFilelength Response.CharSet="UTF-8" Response.ContentType="application/x-download" Response.BinaryWrite S.Read Response.Flush S.Close Set s=Nothing Else Upload.SendBinary StrFileName,True,"application/x-download",False End If End Function %>