Powershell 循环遍历第二个八位字节和第四个八位字节

Powershell loop through 2nd Octets and 4th Octets

首先,我为我对 powershell 的糟糕程度表示歉意。

我正在尝试遍历第二个八位字节 (1-254) 和第四个八位字节 (209-211) IP 地址,return 下面的示例结果。

example ip (2nd octet loop though all possible, then only 4th octet 209 - 211)
10.XXX.88.209 
10.XXX.88.210 
10.XXX.88.211 

example results
10.24.88.209, ABCD0123456
10.88.88.210, ABCD0542857
10.192.88.211, ABCD0123499



$ping = New-Object System.Net.NetworkInformation.Ping
$i = 0
octet = (1..255)
octet = (209..211)
foreach (oct in octet){
    foreach (oct in octet){
        foreach { $ip = "10.oct.11.oct" 
        $Res = $ping.send($ip)

        if ($Res.Status -eq "Success")
        {

        $result = $ip + " = Success"
        Write-Host $result

        $i++

        }
    }
}
 } 
$Hosts = [string]$i
Write-Host $Hosts , $ip

对于你的八位字节,为什么不尝试一些简单的东西,比如

for($second = 1; $second -lt 256; $second++){
    for($fourth = 209; $fourth -lt 212; $fourth++){
        Write-Host "10.$second.88.$fourth"
    }
}