如何用vbscript计算给定范围内的可用ip地址?

时间:2011-05-10 18:55:15

标签: vbscript ip

我有一个ip范围。 192.168.1.0/28所以ips是

192.168.1.1
192.168.1.2
.
.
.
192.168.1.13
192.168.1.14

假设正在使用其中一些ips。这些信息可供我使用。

192.168.1.1
192.168.1.2

现在,我需要计算给定范围内剩余的所有可用地址。答案应该是

192.168.1.3
192.168.1.4
.
.
192.168.1.13
192.168.1.14

如何用vbscript计算呢?
为了使问题变得简单,我使用了一个非常简单的范围,但在现实世界中,我需要在更大的子网上执行此操作。
感谢

1 个答案:

答案 0 :(得分:0)

经过几天的研究。我想出了剧本。这是答案

Dim strAllIP, strUsedIP, strAvailableIps
Dim ynum, xnum, counter, outercounter

ynum = 0
xnum = 0
counter = 0
outercounter = 0

strAllIP = Array("192.168.1.1","192.168.1.2","192.168.1.3", _
                 "192.168.1.4","192.168.1.5","192.168.1.6", _
                 "192.168.1.7","192.168.1.8","192.168.1.9", _
                 "192.168.1.10","192.168.1.11","192.168.1.12", _
                 "192.168.1.13", "192.168.1.14")

strUsedIP = Array("192.168.1.1","192.168.1.2")

For each i in strAllIP


  For each j in strUsedIP
  If i = j Then
  Exit For
  End if
  counter = counter + 1
  If counter - 1 = Ubound(strUsedIP) Then
  Match = True
  Exit for
  End if
  Next

  counter = 0
  If match = True Then
  Redim preserve newarray(outercounter)
  newarray(outercounter)= i
  outercounter = outercounter + 1
  End if
  Match = False

Next

strAvailableIps = join(newarray,chr(13))
msgbox strAvailableIps,0,"Available IPs"