如何在ASP用sql语句查询满足在两个IP字段之间的记录

来源:百度知道 编辑:UC知道 时间:2024/05/05 22:11:06
我做了个网页,可以记录登陆者的IP,但是IP数据库上的记录有的是一个范围,如startip:192.168.0.0 endip:192.168.255并且都是字符串,请问如何能查到192.168.0.25这个IP记录的信息

先用一个自编函数将IP转换成数字,转换成数字,自然就可以指定范围了,列如查询192.168.0.0到192.168.0.255的记录.

userIPnum = IP2Num(rs("IP")) 读取字段的数据进行转换
if userIPnum > IP2Num("192.168.0.0") and userIPnum < IP2Num("192.168.0.255") then
response.write userIPnum&"<br>"
end if

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