解析IP地址,查询数据库的问题
获取浏览者IP地址后,想从数据库中查出浏览者的地区所在,而IP都是文本格式。请问谁能帮我解决这个问题(vbscript)。谢谢。 问题点数:80、回复次数:10Top
1 楼zorou_fatal(The world and system is even)回复于 2003-08-03 09:33:24 得分 40
假设你的数据库里的是这样的
ID IPUpperBound IPLowerBound Address
假设你已经获得ip存在变量
IPClient中。
IPClient_Array=split(IPClient,".")
SQL="select IPUpperBound,IPLowerBound from IAtable order by ID desc"
set rst=server.createobject("adodb.recordset")
rst.open SQL,conn,2,3
while not rst.eof
IPUppBound_Array=split(rst("IPUpperBound"),".")
IPLowBound_Array=split(rst("IPUpperBound"),".")
inthescope=1
for i=0 to 3
if IPClien_Array(i)<=IPUppBound_Array(i) and IPClien_Array(i)>=IPLowBound_Array(i)
inthescope=inthescope*1
else
inthescope=inthescope*0
exit for
next
if inthescope>0 then
response.write rst("address")
rst.movenext
wend
rst.close
set rst=nothingTop
2 楼shangdidewusheng(野马)回复于 2003-08-03 09:46:08 得分 0
忘记说了,数据库的格式是:开始IP地址 结束IP地址 所属地区Top
3 楼zorou_fatal(The world and system is even)回复于 2003-08-03 09:47:39 得分 0
那上面的就可以了。 ^_^Top
4 楼ceocio(成都招聘.Net工程师,有意者请联系我)回复于 2003-08-03 09:49:49 得分 30
see here:
http://expert.csdn.net/Expert/topic/2028/2028457.xml?temp=.5543024Top
5 楼shangdidewusheng(野马)回复于 2003-08-03 13:15:38 得分 0
下面是我的代码,可是只显示一条记录,不知道为什么。麻烦大家看一下
Set Conn=Server.CreateObject("ADODB.Connection")
Set objRs = server.CreateObject("ADODB.RecordSet")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath("f.mdb") & ";"
sql="select * from test order by Data desc"
objRs.open sql, Conn,3,3
<%
for i=1 to objRs.Pagesize
If objRs.eof then
Exit For
Else
%>
<tr bgcolor="#FFFFFF">
<td height="11"><%=objRs("Data")%></td>
<td height="11"><%=objRs("IP")%></td>
<td height="11"><%=IPtoAddr(objRs("IP"))%></td>
<td height="11"><%=objRs("Topage")%></td>
<td height="11">
<% if objRs("Frompage")<>"" then%>
<%=objRs("Frompage")%>
<%else%>
<%="直接输入网址或IP地址"%>
<%end if%>
</td>
</tr>
<%
objRs.MoveNext
end if
next
objRs.close
Conn.close
%>
<%
Private function IPtoAddr(IPstr)
Set Rs=server.CreateObject("ADODB.RecordSet")
sqlstr=" select * from wry order by ID"
Rs.open sqlstr,Conn, 3, 3
for i=1 to Rs.recordcount
if Rs("starIP")<=IPstr and Rs("endIP")<=IPstr then
IPstr=Rs("Addr")
else
Rs.next
end if
next
Rs.close
IPtoAddr=IPstr
end function
%>Top
6 楼possible_Y(████本人签名需要刮开,方可看到 )回复于 2003-08-03 13:38:50 得分 10
google中搜索wry.dllTop
7 楼liaoqingpeng(棋快一步)回复于 2003-08-03 13:57:41 得分 0
请问谁有这样的数据库呀?有的话请给我发一份,再开帖给分。
mail: macrosoft@tom.com
msn: liaoqingpeng@hotmail.com
qq: 34939858Top
8 楼shangdidewusheng(野马)回复于 2003-08-03 15:11:08 得分 0
在不使用<%=IPtoAddr(objRs( "IP "))%>时运行正常,但是加上之后就只显示第一条记录。
请高手帮忙看一下.............在线等待..............
<%
Private function IPtoAddr(IPstr)
Set Rs=server.CreateObject( "ADODB.RecordSet ")
sqlstr= " select * from wry order by ID "
Rs.open sqlstr,Conn, 3, 3
for i=1 to Rs.recordcount
if Rs( "starIP ") <=IPstr and Rs( "endIP ") <=IPstr then
IPstr=Rs( "Addr ")
else
Rs.next
end if
next
Rs.close
IPtoAddr=IPstr
end function
% >Top
9 楼shangdidewusheng(野马)回复于 2003-08-04 12:56:51 得分 0
我把SQL改造成:
objRs.open "select * from test,wry while IPtoNum(IP)>=starIP and IPtoNum(IP)<=endIP order by Data desc" , Conn,3,3
数据库结构:
表wry: ID starIP endIP Addr
(依次为:编号,开始IP地址,结束IP地址,所属地区)
表test: ID IP Time URL
(依次为:编号,浏览者IP地址,访问时间,来源)
错误为:
错误类型:
Microsoft JET Database Engine (0x80040E14)
FROM 子句语法错误。
我正学着做一个后台检测页面,如果嫌点数太少,可以另加。
请高手帮忙看看,我已调试两天了。
Top
10 楼shangdidewusheng(野马)回复于 2003-08-04 13:09:32 得分 0
<%
function IPtoNum(str)
dim ipst
ipst=Split(str,".")
IPtoNum = Cint(ipst(0))*255*255*255 + Cint(ipst(1))*255*255 + Cint(ipst(2)) * 255 + Cint(ipst(3)) - 1
end function
%>Top




