我有这个 powershell 脚本来检查未使用的 IP
$ipgroupes = "192.168.2"
$ipstart = 1
$ipend = 255
$ipstart..$ipend | ForEach-Object{
$ip = "$ipgroupes.0" -replace "0$",$_
If (-not(Resolve-DnsName -Name $ip -QuickTimeout -Type ANY -ErrorAction
SilentlyContinue) -And (!(Test-Connection $ip -count 1 -quiet)))
{
write-host "$ip is not used" -ForegroundColor Green
}
}
脚本工作正常,但我被要求从搜索中排除 ip 80 到 149。我需要有关如何完成此操作的帮助?
最佳答案
试试这个。要撤消排除,您可以将两个排除值设置为 0
$ipgroupes = '192.168.2'
$iprange = 1..255
$excluderange = 80..149
$iprange | Where-Object {$_ -notin $excluderange} | ForEach-Object {
"$ipgroupes.$_"
}
*编辑:在马特的帮助下更新
关于Powershell IP 扫描器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37078053/