循环通过IP地址范围 [英] looping through IP address range

查看:85
本文介绍了循环通过IP地址范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


有没有人有一些代码可以显示如何遍历

范围的IP地址?我正在使用文本框来获取

范围的开始和结束值。我正在考虑使用4个嵌套的for-next循环,但我似乎没有用b / b
在编写

开始和结束地址中的八位字节时遇到问题范围正常。


即172.16.1.1/172.20.1.1应循环172-172,16-20,1-254,1-254

172.16.1.1/172.16.1.254应循环172-172,16-16,1-1,1-254

172.16.1.5/172.16.1.15应循环172-172,16-16,1 -1,5-15

等......


如果没有for-next循环,是否有更简单的方法可以做到这一点?


谢谢,


ne。

Hi all,

Does anyone have some code that shows an example of how to loop through a
range of IP addresses? I''m using text boxes to get a start and end value for
the range. I was thinking about using 4 nested for-next loops, but I seem to
be having trouble working out the logic to validate the octets in the
beginning and ending address so the range works correctly.

i.e. 172.16.1.1/172.20.1.1 should loop 172-172,16-20,1-254,1-254
172.16.1.1/172.16.1.254 should loop 172-172,16-16,1-1,1-254
172.16.1.5/172.16.1.15 should loop 172-172,16-16,1-1,5-15

and so on...

Is there an easier way to do this without for-next loops?

Thanks,

ne.

推荐答案



嗨网络,

您的申请是什么?


Robin

Hi Network,
What is your application?

Robin




" Robin Tucker" < rt ****** @ removehotmail.comwrote in message

news:f2 ******************* @ news.demon。 co.uk ...

"Robin Tucker" <rt******@removehotmail.comwrote in message
news:f2*******************@news.demon.co.uk...

>

嗨网络,


什么是你的应用?
>
Hi Network,
What is your application?



我正在写一个小应用程序来按地址扫描我们的网络地址。我想

能够指定开始和结束地址,以便应用程序可以触及每个

地址,包括结束地址。


很可能是接下来的事情是错误的做法,但我还没有想到,b $ b还有更好的东西。我一直在经历

system.net.ip *和system.networkinformation,但我没有看到任何

看起来很有希望。

I''m writing a little app to scan our network address by address. I want to
be able to specify a start and end address so that the app can touch each
address in between, inclusive of the end addresses.

It may well be that that for-next thing is the wrong approach, but I''ve not
come up with anything better as of yet. I''ve been going through
system.net.ip* and system.networkinformation, but I don''t see anything that
looks promising.




" NetworkElf" < Ne ******** @ nospam.nospamwrote in message

新闻:OK ************** @ TK2MSFTNGP06.phx.gbl .. 。

"NetworkElf" <Ne********@nospam.nospamwrote in message
news:OK**************@TK2MSFTNGP06.phx.gbl...

>

" Robin Tucker" < rt ****** @ removehotmail.comwrote in message

news:f2 ******************* @ news.demon。 co.uk ...
>
"Robin Tucker" <rt******@removehotmail.comwrote in message
news:f2*******************@news.demon.co.uk...

>>
嗨网络,

你的申请是什么?
>>
Hi Network,
What is your application?



我正在写一个小应用程序来按地址扫描我们的网络地址。我想

能够指定开始和结束地址,以便应用程序可以触及每个

地址,包括结束地址。


很可能接下来的事情是错误的做法,但是我还没有想到更好的东西。我一直在经历

system.net.ip *和system.networkinformation,但我看不到任何看起来很有希望的


I''m writing a little app to scan our network address by address. I want to
be able to specify a start and end address so that the app can touch each
address in between, inclusive of the end addresses.

It may well be that that for-next thing is the wrong approach, but I''ve
not come up with anything better as of yet. I''ve been going through
system.net.ip* and system.networkinformation, but I don''t see anything
that looks promising.



嵌套循环有什么问题? Loosk喜欢它会工作正常:


Dim Oct1 As Integer = 0

Dim Oct2 As Integer = 0

Dim Oct3 As整数= 0

Dim Oct4 As Integer = 0


对于Oct1 = 0到255

对于Oct2 = 0到255

对于Oct3 = 0到255

对于Oct4 = 0到255

Dim ipAddress作为新的StringBuilder

ipAddress。追加(Oct1.ToString)

ipAddress.Append("。")

ipAddress.Append(Oct2.ToString)

ipAddress。追加(。)

ipAddress.Append(Oct3.ToString)

ipAddress.Append("。")

ipAddress.Append(Oct4.ToString)

SubToScanAddress(ipAddress.ToString)

Next Oct4

Next Oct3

下一个Oct2

下一个Oct1


您可能想要对诸如用于
多播和广播内容的地址进行一些过滤但这似乎有效。

Whats wrong with the nested loops? Loosk like it would work fine:

Dim Oct1 As Integer = 0
Dim Oct2 As Integer = 0
Dim Oct3 As Integer = 0
Dim Oct4 As Integer = 0

For Oct1 = 0 to 255
For Oct2 = 0 to 255
For Oct3 = 0 to 255
For Oct4 = 0 to 255
Dim ipAddress As New StringBuilder
ipAddress.Append(Oct1.ToString)
ipAddress.Append(".")
ipAddress.Append(Oct2.ToString)
ipAddress.Append(".")
ipAddress.Append(Oct3.ToString)
ipAddress.Append(".")
ipAddress.Append(Oct4.ToString)
SubToScanAddress(ipAddress.ToString)
Next Oct4
Next Oct3
Next Oct2
Next Oct1

You might want to do some filtering on things like the addresses used for
multicast and broadcast stuff but this would seem to work.


>
>



这篇关于循环通过IP地址范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆