February 9, 2006


限制某段IP地址/給數據庫建立防下載表以文找文

在網上看到的兩段代碼,先貼在這裡備用。

1、限制某段IP地址
function IP2Num(sip)
    dim str1,str2,str3,str4
    dim num
    IP2Num=0
    if isnumeric(left(sip,2)) then
        str1=left(sip,instr(sip,".")-1)
        sip=mid(sip,instr(sip,".")+1)
        str2=left(sip,instr(sip,".")-1)
        sip=mid(sip,instr(sip,".")+1)
        str3=left(sip,instr(sip,".")-1)
        str4=mid(sip,instr(sip,".")+1)
        num=cint(str1)*256*256*256+cint(str2)*256*256+cint(str3)*256+cint(str4)-1
        IP2Num = num
    end if
end function

userIPnum = IP2Num(Request.ServerVariables("REMOTE_ADDR"))

if userIPnum > IP2Num("192.168.0.0") and userIPnum < IP2Num("192.168.0.255") then
    response.write ("<center>您的IP被禁止</center>")
    response.end
end if

2、給數據庫建立防下載表(二進制表,數據庫後綴必須為.asp)

<%
Dim DB,RS,SQL
DB = "DB.asp"    '這裡改成您的數據庫,一定要是asp後綴
Set Conn = Server.CreateObject("Adodb.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath(db)
Conn.Execute("Create Table NotDownload(NotDown OLEObject)")
Set RS = Server.CreateObject("ADODB.RecordSet")
SQL = "Select * FROM NotDownload"
RS.Open SQL,Conn,1,3
RS.Addnew
RS("NotDown").appendchunk(chrB(Asc("<")) & chrB(Asc("%")))
RS.Update
RS.Close
Set RS = Nothing
Conn.Close
Set Conn = Nothing
Response.Write "數據庫防下載處理完成,請確認您的Access數據庫已經改為ASP後綴"
%>



Posted by at 天空部落 │13:54 │回應(1)引用(0)網頁設計筆記
相關閱讀

引用URL

http://blog.yam.com/ezkm/trackback/5683221
回應文章
謝謝您的方法!
Posted by Chung Chyuan-Bing at 2007-02-15 13:24:53