,但我想要的是驗證CIDR塊是在其他CIDR塊像蔚藍的門戶網站做了驗證範圍,同時創建虛擬網絡和子網
對於CIDR範圍比較,我認爲你可以從IPNetwork充分利用IPNetwork.Contains
方法如下:
IPNetwork addressSpaceRange = IPNetwork.Parse("172.20.0.0/24");
IPNetwork subnetAddressRange = IPNetwork.Parse("172.20.0.0/25");
Console.WriteLine($"Address space [{addressSpaceRange.ToString()}]:");
Console.WriteLine($"FirstUsable address:{addressSpaceRange.FirstUsable}");
Console.WriteLine($"LastUsable address:{addressSpaceRange.LastUsable}\r\n");
Console.WriteLine($"Subnet address range [{subnetAddressRange.ToString()}]:");
Console.WriteLine($"FirstUsable address:{subnetAddressRange.FirstUsable}");
Console.WriteLine($"LastUsable address:{subnetAddressRange.LastUsable}\r\n");
Console.WriteLine("addressSpaceRange contains subnetAddressRange:" + IPNetwork.Contains(addressSpaceRange, subnetAddressRange));
輸出
![enter image description here](https://i.stack.imgur.com/PkAOT.png)
![enter image description here](https://i.stack.imgur.com/6EnLT.png)
![enter image description here](https://i.stack.imgur.com/zpR3B.png)
而且,根據我的測試,這種方法只檢查子網地址範圍是否是由地址空間包含的,我假設驗證的子網地址和地址檢查將在Azure方面處理。
到目前爲止你有什麼嘗試?你的代碼中哪部分是錯誤? – astaykov
實際上我沒有找到任何驗證cidr範圍下的cidr範圍的代碼。我發現它的代碼只驗證CIDR範圍內的IP,而不驗證CIDR範圍內的CIDR範圍。 –