#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         {}               {}

About the author: Ravikanth C

Ravikanth is the founder and editor of the PowerShell Magazine. He is also a PowerShell MVP who works at Dell Inc. He blogs at http://www.ravichaganti.com/blog and you can follow him on Twitter @ravikanth.

Related Posts