日期:2014-05-17  浏览次数:20926 次

代码求救
<%
dim   ip
dim   a
dim   address
ip=request.servervariables( "remote_addr ")
for   a=1   to   254
address= "192.168.7. "&a  
next
%>
我现在想让来访者的ip是在address= "192.168.7. "&a的定义之中,下面的代码应该怎么写啊。现在能循环出来,但是怎么比较啊。我写了,但是有错误。

------解决方案--------------------
给你一个函数,把IP转成整数,然后再比较

Function GetIPNum(IP_Num)
Dim IPNum0,IPNum1,IPNum2,IPNum3,IPNum4
IPNum0 = Trim(IP_Num)
IPNum1 = Left(IPNum0,Instr(IPNum0, ". ")-1)
IPNum0 = Mid(IPNum0,Instr(IPNum0, ". ")+1)
IPNum2 = Left(IPNum0,instr(IPNum0, ". ")-1)
IPNum0 = Mid(IPNum0,Instr(IPNum0, ". ")+1)
IPNum3 = Left(IPNum0,instr(IPNum0, ". ")-1)
IPNum4 = Mid(IPNum0,Instr(IPNum0, ". ")+1)
GetIPNum = Cint(IPNum1)*256*256*256+Cint(IPNum2)*256*256+Cint(IPNum3)*256+Cint(IPNum4)-1
End FuncTion
------解决方案--------------------
<%
dim ip
dim a
dim address
ip=request.servervariables( "remote_addr ")
for a=1 to 254
address= "192.168.7. "&a
if ip=address then
response.write "在范围内 "
endif
next
%>

------解决方案--------------------
function show(ip)
{
var objip= ip.value.split( ". ");
if (objip.length ==4)
{
//判断objip[3]是否在1-254之间
}
}
------解决方案--------------------
楼主是想判断来访IP是不是在你定义的固定IP范围内?
也就是192.168.7.x这一个单独的网段内?
如果是这样,好办

ip=request.servervariables( "remote_addr ")
if ip= " " then ip= "127.0.0.1 "
else
dim aIp:aIp=split(ip, ". ")
dim newStr:newStr=aIp(0)& ". "&aIp(1)& ". "&aIp(2)
end if
if newStr <> "192.168.7 " then
.........
else
.............
end if