Resolve IP-Addresses

by Mar 22, 2011

This one-liner accepts one or more IP-addresses and will try to resolve the address. If DNS returns valid information, you will receive the host name and aliases. If not, you will get a warning with the cause:

'127.0.0.1', '127.0.0.2', '10.10.10.11' | `
Foreach-Object { $ip = $_ `
try { [System.Net.DNS]::GetHostByAddress($_) } `
catch { Write-Warning "Unable to resolve $ip. Reason: $_" } }

To analyze a network segment, you should try something like this (adjust the IP segment to match yours):

1..255 | Foreach-Object { "192.168.1.$_" } | `
Foreach-Object { $ip = $_ `
try { [System.Net.DNS]::GetHostByAddress($_) } catch `
{
Write-Warning "Unable to resolve $ip. Reason: $_" } }

 

Twitter This Tip!
ReTweet this Tip!