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 | VMware vExpert 2017, 2018, 2019, 2020 | VMCE | Slovak VMUG Leader |  user group ambassador for kmug.sk | husband&father

Leave a Reply

Your email address will not be published. Required fields are marked *