Kontrola obsadenosti IP rozsahu

Aj najzodpovednejším administrátorom sa stane, že si zabudnú aktualizovať zoznam IP adries ktoré používajú. Preto sa hodí, raz za čas “opingať” celý rozsah.Výsledkom je zoznam:

  • IP adresy, ktoré nepingajú
  • DNS záznamy pridelené daným IP adresám
$ping = New-Object System.Net.NetworkInformation.Ping
$ipr = "192.168.1" # ip rozsah
$report = "C:\Scripts\Exports\FreeIP-$ipr-{0:yyyyMMdd}.csv" -f (Get-Date)
"IP,DNSName" | Add-Content $report

1..254 | foreach { 
                          $ip = "$($ipr).$_"
                          $Res = $ping.send($ip)

                          if ($Res.Status -ne "Success") {
                                   $ResolveDNS = Resolve-DnsName -Server 192.168.100.120 -Name $ip -ErrorAction SilentlyContinue | Select-Object -ExpandProperty NameHost -First 1
                                   if ($ResolveDNS -ne $NULL){
                                                                      $result = $ip + ",$($ResolveDNS)"
                                                                      $result | Add-Content $report
                                                                      Write-Host $result
                                                                      }
                           else {
                                   $result = $ip + ",DNS name does not exist"
                                   $result | Add-Content $report
                                   Write-Host $result
                                   }
                           }
}

Author: Martin

Infrastructure engineer | virtualization & cloud enthusiast | vSphere specialist | blogger | Veeam Vanguard 2021,2022,2023 | VMware vExpert 2017 - 2024 | VMCE | VCP-DCV, NV, TKO, VCAP-DCV | Slovak VMUG Leader | Slovak VUG Leader | husband&father