【发布时间】:2017-10-16 15:07:50
【问题描述】:
我正在尝试编写一个脚本,它会为 DHCP 设备找到(并稍后添加预留)。我遇到的问题是有一个范围,在这个范围内,我们手动划分了不同的 IP 范围,应该添加某种类型的设备。
例如范围 10.92.0.0/24 我们将范围分配为
10.92.0.10-20 适用于 iPhone 等。 10.92.0.10.50 适用于 Android 手机等
我知道脚本可以通过我提供给它的 IP 范围,并获取 DHCP 保留或显示错误。我一直在想第一个Error可以作为免费IP。
有什么想法吗? :)
# Get DHCP Scope
$Start = 100
$End = 140
$DHCPServer = "dhcpserver.company.com"
# Find Free IP address
#It can use to get DHCP reservation by IP and find the one which returns error - which can be used as the free one - loop done
#Now how to tell it to stop when the error occures?
While ($Start -le $End) {
$IP = "10.92.0.$Start"
Write-Host "Reservation for: $IP" -ForegroundColor Cyan
Get-DhcpServerv4Reservation -ComputerName $DHCPServer -IPAddress $IP
$Start++
}
【问题讨论】:
标签: windows powershell server dhcp