Home / Articles / Scripts / Resolve a list of IPs to their DNS names

Resolve a list of IPs to their DNS names

Below is a powershell script that will resolve a list of IPs to their respective DNS names:

 

# The following line read a plain list of IPs from files.
$listofIPs = Get-Content “C:IPList.txt”
#create a blank array for the resolved names
$ResultList = @()
#resolve each of these addresses
foreach ($ip in $listofIPs)
{
$result = $null
$currentEAP = $ErrorActionPreference
$ErrorActionPreference = “silentlycontinue”
#Use the DNS Static .Net class for the reverse lookup
$result = [Net.Dns]::gethostentry($ip)
$ErrorActionPreference = $currentEAP
If ($Result)
{
$Resultlist += [string]$Result.HostName

}
Else
{
$Resultlist += “$IP – No HostNameFound”
}
}
#Output to file
$resultlist | Out-File “C:IPList_Output.txt”

Please let Denver IT Services firm NOYNIM if you need any other scripts that may be useful

Share


Comment on Resolve a list of IPs to their DNS names

Leave a Reply






Contact Us