#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> [Net.DNS]::GetHostEntry("server01")
HostName Aliases AddressList
-------- ------- -----------
server01 {} {192.94.21.28}
PS C:\> [Net.DNS]::GetHostEntry("192.94.21.28")
HostName Aliases AddressList
-------- ------- -----------
server01 {} {}
Share on: