列出IP子网中的所有地址 [英] List IP all addresses in a subnet
问题描述
我需要获取子网中包含的所有IP地址,而我正尝试使用 IPnetwork
I need to get all of the IP addresses contained in within a subnet and I'm trying to do it using IPnetwork
例如,子网192.168.1.0/29将具有以下输出:
For example the subnet 192.168.1.0/29 would have the following output:
// Output
// 192.168.1.0
// 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
这是我的代码:
IPNetwork ipn = IPNetwork.Parse("192.168.1.0/29");
IPAddressCollection ips = IPNetwork.ListIPAddress(ipn);
foreach (IPAddress ip in ips)
{
Console.WriteLine(ip);
}
// Output
// 192.168.1.0
// 192.168.1.0
// 192.168.1.0
// 192.168.1.0
// 192.168.1.0
// 192.168.1.0
您会看到,这不是理想的结果。我想念什么?还有其他工具或方法可以完成这项工作吗?我设法破解了一些东西,但是它不是很漂亮,我不确定它是否正确地枚举了更大的子网。
As you can see, this is not the desired result. What am I missing? Is there another tool or method to get this job done? I have manage to hack something up, but it ain't pretty and I'm not sure if it's properly enumerating larger subnets.
推荐答案
ipnetwork库已更新(至1.3.1版),其中包含修补程序和测试单元,以解决此问题。
可以从 IPnetwork
ipnetwork library has been updated (to version 1.3.1) with patch and a testunit covering this issue. It can be downloaded at IPnetwork
这篇关于列出IP子网中的所有地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!