Get-PublicDnsRecord.ps1
something exciting
Some information about the exciting thing
Table of contents generated with markdown-toc
Script
Function Get-PublicDnsRecord {
<#
.SYNOPSIS
Make some DNS query based on Stat DNS.
.DESCRIPTION
Use Invoke-WebRequest on Stat DNS to resolve DNS query.
.EXAMPLE
Get-PublicDnsRecord -DomaineNAme "ItForDummies.net" -DnsRecordType A,MX
.EXAMPLE
Get-PublicDnsRecord -DomaineNAme "www.valbox.fr" -DnsRecordType A,MX
.PARAMETER DomainName
Domain name to query.
.PARAMETER DnsRecordType
DNS type to query.
.INPUTS
.OUTPUTS
.NOTES
.LINK
#>
Param(
[Parameter(Mandatory = $true,
HelpMessage = 'DNS domain name to query.',
Position = 1)]
[String]$DomainName,
[Parameter(Mandatory = $true,
HelpMessage = 'DNS record type to query.',
Position = 2)]
[ValidateSet('A', 'AAAA', 'CERT', 'CNAME', 'DHCIP', 'DLV', 'DNAME', 'DNSKEY', 'DS', 'HINFO', 'HIP', 'IPSECKEY', 'KX', 'LOC', 'MX', 'NAPTR', 'NS', 'NSEC', 'NSEC3', 'NSEC3PARAM', 'OPT', 'PTR', 'RRSIG', 'SOA', 'SPF', 'SRV', 'SSHFP', 'TA', 'TALINK', 'TLSA', 'TXT')]
[String[]]$DnsRecordType
)
DynamicParam {
$AttribColl = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute]
$ParamAttrib = New-Object -TypeName System.Management.Automation.ParameterAttribute
$ParamAttrib.Mandatory = $false
$ParamAttrib.ParameterSetName = '__AllParameterSets'
$ParamAttrib.ValueFromPipeline = $false
$ParamAttrib.ValueFromPipelineByPropertyName = $false
$AttribColl.Add($ParamAttrib)
$AttribColl.Add((New-Object -TypeName System.Management.Automation.ValidateSetAttribute -ArgumentList ((Invoke-WebRequest -Uri 'http://www.dns-lg.com/nodes.json' | Select-Object -ExpandProperty Content | ConvertFrom-Json | Select-Object -ExpandProperty nodes | Select-Object -ExpandProperty name))))
$RuntimeParam = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter -ArgumentList ('Node', [string], $AttribColl)
$RuntimeParamDic = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary
$RuntimeParamDic.Add('Node', $RuntimeParam)
$RuntimeParamDic
}
Begin {
$PsBoundParameters.GetEnumerator() | ForEach-Object -Process { New-Variable -Name $_.Key -Value $_.Value -ErrorAction 'SilentlyContinue' }
if (!$Node) { $Node = Invoke-WebRequest -Uri 'http://www.dns-lg.com/nodes.json' | Select-Object -ExpandProperty Content | ConvertFrom-Json | Select-Object -ExpandProperty nodes | Select-Object -ExpandProperty name | Get-Random }
}
Process {
ForEach ($Record in $DnsRecordType) {
Try {
$WebUrl = 'http://www.dns-lg.com/{0}/{1}/{2}' -f $Node, $DomainName, $Record
Write-Verbose -Message "Constructed URL for query is $WebUrl."
$WebData = Invoke-WebRequest -Uri $WebUrl -ErrorAction Stop | Select-Object -ExpandProperty Content | ConvertFrom-Json | Select-Object -ExpandProperty answer
$WebData | % {
New-Object -TypeName PSObject -Property @{
'Name' = $_.name
'Type' = $_.type
'Target' = $_.rdata
'Node' = $Node
}
}
}
catch {
Write-Warning -Message $_
New-Object -TypeName PSObject -Property @{
'Name' = $DomainName
'Type' = $Record
'Target' = ($_[0].ErrorDetails.Message -split '"')[-2]
'Node' = $Node
}
}
}
}
End {}
}
Download
Please feel free to copy parts of the script or if you would like to download the entire script, simple click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.
Report Issues
You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.