Hey all,
I am trying to do a reverse DNS lookup (ip to hostname) on a list of IP's that I have in a txt file. There are ~460 addresses so I would obviously prefer not doing this manually.
After much googling, I have come up with this.
$listofIPs = Get-Content c:\iplist.txt
foreach($i in $listofips)
{
try
{
$ip = $i
$HostName = [System.Net.Dns]::GetHostByAddress($ip).HostName
Test-Connection $HostName -Count 1
}
catch
{
Write-Warning "Cannot resolve $ip"
continue
}
}
The command seems to execute but I get a "WARNING: Cannot resolve (IP Address)" error for every IP address that is in my file. It seems to parse the addresses correctly and when I use the
$IP = “(IP Address)”
[System.Net.Dns]::GetHostEntry($IP)
command, it resolves the IP just fine.
I am a complete n00b when it comes to PS and this is probably a super easy fix, but I need help! Thanks ahead of time!