获取子网中可用IP地址的列表 [英] get list of available ip addresses in subnet

查看:133
本文介绍了获取子网中可用IP地址的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取子网中可用IP地址的列表? 我能够获取所有IP地址的列表,但无法检查IP地址是否已被利用.由于某种原因,以下命令不起作用. Test-AzureRmPrivateIPAddressAvailability

How can i get the list of available ip address in a subnet? I was able to get the list of all ip addresses but not able to check if the ip address is already utilized. for some reason the below command doesn't work. Test-AzureRmPrivateIPAddressAvailability

非常感谢.

推荐答案

由于某种原因,以下命令不起作用. Test-AzureRmPrivateIPAddressAvailability

For some reason the below command doesn't work. Test-AzureRmPrivateIPAddressAvailability

我们可以像这样使用Test-AzureRmPrivateIPAddressAvailability:

We can use Test-AzureRmPrivateIPAddressAvailability like this:

PS C:\> Get-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgname | Test-AzureRmPrivateIPAddressAvailability -IPAddress "10.0.1.10"

我们还可以使用PowerShell在子网中列出可用的IP地址,这是我的脚本:

Also we can use PowerShell to list available ip address in a subnet, here is my script:

PS C:\> $vnet = Get-AzureRmVirtualNetwork -Name "vnet" -ResourceGroupName "jason"
PS C:\> $networkID = "10.0.0."
PS C:\> For ($i=1; $i -lt 255; $i++)
>> {
>>     $IP = $networkID + $i
>>     $Address = Test-AzureRmPrivateIPAddressAvailability -VirtualNetwork $vnet -IPAddress $IP
>>     If ($Address.Available –eq $False) { Write-Host "$IP is not available" -ForegroundColor Red }
>>     else { Write-Host "$IP is available" -ForegroundColor Green}
>> }
10.0.0.1 is not available
10.0.0.2 is not available
10.0.0.3 is not available
10.0.0.4 is not available
10.0.0.5 is available
10.0.0.6 is available
10.0.0.7 is available
10.0.0.8 is available
10.0.0.9 is available
10.0.0.10 is available

这篇关于获取子网中可用IP地址的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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