如何判断一个IP是否属于一个IP区间?

请问如何判断一个IP是否属于一个IP区间?比如判断200.13.1.100是否属于200.13.1.1(ip段1)-200.13.1.200(ip段2).最好能提供给我一段代码(vbs)因为我现在一点思路都没有,不知道该怎么样循环.
---------------------------------------------------------------
zorou_fatal(代码比人可爱) :

恩,比如

IPstart="200.13.1.1"
IPend="200.13.1.200"
Array_IPstart=split(Ipstart,".")
Array_IPend=split(Ipend,".")
如果要判断的IP在变量Target里,可以
Target="200.13.1.100"
Array_Target=split(Target,".")
Dim into
into=1
for int i=0 to 3
if Array_Target(i)<=Array_IPend(i) and Array_Target(i)>=Array_IPstart(i) then
into=into1
else
into=into
0
end if
next

最后判断
if i=1 then
response.write "在范围内"
else
response.write "不在范围内"
end if

---------------------------------------------------------------
liudong963(东仔) :
zorou_fatal(代码比人可爱) 编写的处理程序不愧为好程序,但是遇到IP地址使用了通配符(*)和下面情况好像就不行了:
IPstart="200.13.1.1"
IPend="200.13.2.0"

根据需要我也编写了一段,效率虽然不高,但是功能还算强大,呵呵

Function getDbl(byVal IP,Cvalue)
Dim regEx, Matches, DataStr
IP=IP&"."

Set regEx = New RegExp
regEx.Pattern = "(\d){1,3}."
regEx.Global = True

Set Matches = regEx.Execute(Replace(IP,"*",Cvalue))
DataStr=Matches.Item(0).Value _
&Space(4-Matches.Item(1).Length)&Matches.Item(1).Value _
&"" _
&Space(4-Matches.Item(2).Length)&Matches.Item(2).Value _
&Space(4-Matches.Item(3).Length)&Matches.Item(3).Value
DataStr=Replace(Replace(Replace(DataStr," ","0"),".",""),"
",".")
getDbl=CDbl(DataStr)
End Function

Function IPTest(byVal startIP,byVal endIP,byVal testIP)
If Instr(startIP,"*")

1<instr(endip,"*") and="" getdbl(endip,255)="" iptest="(getDbl(startIP,0)&lt;=getDbl(testIP,0)" startip="endIP" then="">=getDbl(testIP,255))   
2End Function   
3  
4'测试结果   
5IPTest("200.13.1.1","200.13.1.200","200.13.1.100") 'true   
6IPTest("200.13.1.*","200.13.*.*","200.13.23.100") 'true   
7IPTest("200.13.1.1","200.13.1.*","200.13.1.26") 'true   
8IPTest("200.13.*.*","200.13.1.*","200.13.1.100") 'true</instr(endip,"*")>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus