<%@language=vbscript codepage=936%>
<html>
<head>
<title>untitled document</title>
<meta http-equiv=content-type content=text/html; charset=gb2312>
</head>
<body>
<%
dim finishgetip,showip,allip
'///////////////////////////////////////////////// ///////////////////////////////////////
'程序還不是很精簡,以後再修改
'本程序所用的數據庫為-- “馮志宏”-- 所寫的--“追捕”--軟件中所帶ip數據庫和
' “國華軟件guohua soft”的作者--“馮國華”—所寫的“全球ip地址分配表.chm”合二為一得到的
'感謝“馮志宏”和“馮國華”提供的數據
'數據庫中還有不少的重複ip地址,希望有心人能將其刪除,減小數據庫
'我的程序寫的還很笨拙,希望大家能多提意見,多多交流,謝謝!
'///////////////////////////////////////////////// ///////////////////////////////////////
'解決思路:
'取得的客戶端ip一般是202.11.25.1這種,而數據庫中的ip格式為202.011.025.001,這就需要將取得的
'客戶端ip轉換為與數據庫中ip一樣的格式
'因為目前我們所用的ip是分為4段,每段3位,中間以“.”分隔
'所以我的思路是將客戶端ip以“.”符號分割為4段,即202/11/25/1
'然後再分別核對每一段,如果是3位,則不變;如不足3位,為2位,該段前補1個0,為1,同理,則補2個0
'得到格式化後的ip後,去掉ip的最後一段,即取包括“.”的前11位,與數據庫中的startip字段的前11位相比較,查找相同的值
'因為從數據庫中可以看到,startip和endip的前三段都是一樣的,而最後一段不過是內部子網地址,可以去掉
'所以只要取startip或endip的任意一個字段的前11位與客戶端ip的前11位相比較就可以查到正確的所在地
'///////////////////////////////////////////////// ////////////////////////////////////////
function checkip_trueip()
'取客戶端真實ip
getclientip = request.servervariables(http_x_forwarded_for) '如果客戶端用了代理服務器,則用request.servervariables(remote_addr)方法只能得到空值,則應該用servervariables(http_x_forwarded_for)方法
if getclientip = then
getclientip = request.servervariables(remote_addr)'如果客戶端沒用代理,則request.servervariables(http_x_forwarded_for)得到是空值,應該用request.servervariables(remote_addr)方法
end if
checkip_trueip = getclientip
end function
'///////////////////////////////////////////////// ////////////////////////////
function getaccessrecordset(db,sql,mark,read)'取得recordset對象
set conn=getaccessconn(db)'輸入參數為db-數據庫的相對路徑,sql-sql語句,mark,read為數據庫讀取方式,1,1為只讀,1,3為讀寫
'constr=provider=microsoft.jet.oledb.4.0;&data source=&server.mappath(db)
' conn.open constr
set getaccessrecordset=server.createobject(adodb.recordset)
getaccessrecordset.open sql,conn,mark,read
end function
'///////////////////////////////////////////////// /////////////////////////
function getaccessconn(db)'取得connection對象
set getaccessconn=server.createobject(adodb.connection)
'constr=driver={microsoft access driver (*.mdb)};dbq=&server.mappath(allcon/#bbsall.mdb)
constr=provider=microsoft.jet.oledb.4.0;&data source=&server.mappath(db)
getaccessconn.open constr
end function
'///////////////////////////////////////////////// ////////////////////////
dim getip
'getip=(trim(request.servervariables(remote_addr)))'從客戶端獲取ip
'getip=(trim(request.querystring(comes))) '自己輸入ip測試
'response.write(getip&<br>)
'///////////////////////////////////////////////// ///////////////////////
function checkip_locations(checkstring) '返回ip中分隔字符的位置函數
checkip_locations=instr(checkstring,.) '將位置的值賦予給函數
end function
'///////////////////////////////////////////////// //////////////////////
'以下函數為分割ip,取得每次分割後“.”符號右邊的ip剩餘的字符串
function checkip_left(checkstring)
locations_left=checkip_locations(checkstring) '得到在ip剩餘的字符串中“.”第一次出現的位置
iplength_left=len(checkstring) '取得ip剩餘的字符串的長度
divide_locations_left=iplength_left-locations_left '取得在ip剩餘的字符串中“.”第一次出現的位置,從右往左數是多少位
ipstr_left=right(checkstring,divide_locations_left) '取得本次分割後,“.”符號右邊的ip剩餘的字符串
checkip_left=ipstr_left '將上面得到的字符串賦給函數
end function
'///////////////////////////////////////////////// //////////////////////
'以下函數為分割ip,取得每次分割後“.”符號左邊的ip字符串,即將ip分為四段,每一段的字符串
function checkip_right(checkstring)
locations_right=checkip_locations(checkstring) '取得在ip中“.”第一次出現的位置
iplength_right=len(checkstring) '取得ip字符串長度
divide_locations_right=iplength_right-locations_right '取得在ip剩餘的字符串中“.”第一次出現的位置,從右往左數是多少位
ipstr11=trim(replace(left(checkstring,locations_right),.,)) '將得到的“.”左邊的字符串去掉.符號
'如果ip分為4段後每一段不足3位則補0
if len(ipstr11)=2 then ipstr11=0&ipstr11
if len(ipstr11)=3 then ipstr11=ipstr11
if len(ipstr11)=1 then ipstr11=00&ipstr11
checkip_right=ipstr11 '得到“.”符號之前的字符串,即本次分割後得到的ip分割為四段後其中的一段
end functi
國內最大的酷站演示中心!