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

发布于 2024-11-06 06:34:43 字数 426 浏览 1 评论 0原文

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

192.168.1.1
192.168.1.2
.
.
.
192.168.1.13
192.168.1.14

假设其中一些 ip 正在被使用。这些信息对我来说是可用的。

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 计算这个?
为了使问题变得简单,我使用了一个非常简单的范围,但在现实世界中,我需要在更大的子网上执行此操作。
谢谢

I have an ip range. 192.168.1.0/28 so ips are

192.168.1.1
192.168.1.2
.
.
.
192.168.1.13
192.168.1.14

Let's say some of these ips are being used. And this information is available to me.

192.168.1.1
192.168.1.2

Now, I need to calculate all the available addresses left in the range given. Answer should be

192.168.1.3
192.168.1.4
.
.
192.168.1.13
192.168.1.14

How can I calculate this with vbscript?
I have used a very easy range for the sake of making the question simple but in real world I need to perform this operation on much larger subnets.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

衣神在巴黎 2024-11-13 06:34:43

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

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"

After a few days of research. I figured out the script. Here's the answer

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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文