-
Notifications
You must be signed in to change notification settings - Fork 29
/
Get-Dns.ps1
43 lines (36 loc) · 1.32 KB
/
Get-Dns.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<#
.SYNOPSIS
Looks up DNS info, given a hostname or address.
.INPUTS
System.String of host names to look up.
.OUTPUTS
System.Net.IPHostEntry of host DNS entries, or
System.String of network addresses found.
.LINK
https://msdn.microsoft.com/library/ms143998.aspx
.EXAMPLE
Get-Dns.ps1 www.google.com
HostName Aliases AddressList
-------- ------- -----------
www.google.com {} {172.217.10.132}
#>
[CmdletBinding()][OutputType([Net.IPHostEntry])][OutputType([string])] Param(
# A host name or address to look up.
[Parameter(Position=0,Mandatory=$true,ValueFromRemainingArguments=$true,ValueFromPipeline=$true)]
[Alias('Address','HostAddress','Name')][string[]] $HostName,
<#
Indicates that only the string versions of addresses belonging to the specified family should be returned.
"Unknown" returns all addresses.
#>
[Net.Sockets.AddressFamily] $OnlyAddresses
)
Process
{
foreach ($h in $HostName)
{
$entry = [Net.Dns]::GetHostEntry($h)
if(!$PSBoundParameters.ContainsKey('OnlyAddresses')) {$entry}
elseif($OnlyAddresses -eq [Net.Sockets.AddressFamily]::Unspecified) {$entry.AddressList |ForEach-Object {$_.IPAddressToString}}
else {$entry.AddressList |Where-Object AddressFamily -eq $OnlyAddresses |ForEach-Object {$_.IPAddressToString}}
}
}