#PSTip Resolving an IP Address to host name and vice versa using .NET

Note: This tip requires PowerShell 1.0 or above.

In an earlier tip, we showed you how to resolve IP addresses using WMI. In PowerShell, there is always more than one way to achieve anything. So, in today’s tip, let us see how to use System.Net.Dns .NET class to achieve the same. In this .NET class, the GetHostEntry() method can be used to resolve IP address to host name and vice versa.

Here is how we use this method.

PS C:\> [Net.DNS]::GetHostEntry("server01")

HostName          Aliases          AddressList
--------          -------          -----------
server01          {}               {}

PS C:\> [Net.DNS]::GetHostEntry("")

HostName         Aliases          AddressList
--------         -------          -----------
server01         {}               {}
Filed in: Columns, Tips and Tricks Tags: , , ,
© 6517 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: