In this case we’re going to use the method GetHostAddresses of the Dns class of the Sytem.Net namespace.
For PowerShell 2.0 you can use following Windows PowerShell One Liners:
Name to IP Address (DNS Forward)
1
2
| [System.Net.Dns]::GetHostAddresses('graef.io')
[System.Net.Dns]::GetHostAddresses('graef.io').IPAddressToString
|
IP Address to Name (DNS Reverse)
1
2
3
4
5
| [System.Net.Dns]::GetHostbyAddress('85.13.135.42')
HostName Aliases AddressList
-------- ------- -----------
graef.io {} {85.13.135.42}
|
As of PowerShell 4.0 you can use the Cmdlet Resolve-DnsName as well as for both Forward and Reverse:
1
2
3
4
5
6
7
8
9
10
11
12
| Resolve-DnsName graef.io
Name Type TTL Section IPAddress
---- ---- --- ------- ---------
graef.io AAAA 72711 Answer 2a01:488:42:1000:50ed:84e8:ff91:1f91
graef.io A 72711 Answer 80.237.132.232
Resolve-DnsName 80.237.132.232
Name Type TTL Section NameHost
---- ---- --- ------- --------
232.132.237.80.in-addr.arpa PTR 32738 Answer graef.io
|