28,391
社区成员
发帖
与我相关
我的任务
分享
<%
userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If userip = "" Then userip = Request.ServerVariables("REMOTE_ADDR")
'先用一个自编函数将IP转换成数字,转换成数字,自然就可以指定范围了,列如查询192.168.0.0到192.168.0.255的记录.
userIPnum = GetIpNum(userip) '读取客户真实IP转换
set rs=server.CreateObject("adodb.recordset")
rs.open"select * from abcip ",conn,1,1
do while not rs.eof
if userIPnum > IP2Num(rs("startip")) and userIPnum < IP2Num(rs("endip")) then
response.write userip
response.write ("<br>")
response.write (rs("country"))
end if
rs.movenext
loop
rs.close
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
%>