Get Public Dns Record Value PowerShell

Get Public Dns Record Value PowerShell

Hello,

Nslookup is great, but it’s an old exe tool, and PowerShell is the new way to go. Thanks to .Net, we go the System.Net.dns class, with two methods:

  • GetHostByName
  • Resolve
Get Public Dns Record Value - System.Net.Dns

Get Public Dns Record Value – System.Net.Dns

But none of these allow us as much flexibility as nslookup do. You can specify a record type, you can specify which DNS server to use.

Be cause of those needs, we need another solution, a friend of mine, Thomas, showed a web service named “DNS LG” which offer that kind of features.

If you look at the documentation, you can see that the API is quite easy to use:

Get Public Dns Record Value PowerShell - API Use Exemple

Get Public Dns Record Value PowerShell – API Use Exemple

Get Public Dns Record Value PowerShell - API Use Exemple Legend

Get Public Dns Record Value PowerShell – API Use Exemple Legend

Let’s try with a domaon of ours:

http://www.dns-lg.com/google1/itfordummies.net/txt

Get Public Dns Record Value PowerShell - API Answer Exemple

Get Public Dns Record Value PowerShell – API Answer Exemple

We can see a JSON formatted answer, let’s try to use this with PowerShell:

Invoke-WebRequest -Uri "http://www.dns-lg.com/google1/itfordummies.net/txt" | Select-Object -ExpandProperty Content | ConvertFrom-Json | Select-Object -ExpandProperty answer
Get Public Dns Record Value PowerShell - API Answer Exemple with PowerShell

Get Public Dns Record Value PowerShell – API Answer Exemple with PowerShell

And voilĂ  !

You can use the API will all of those kind of DNS record types:

  • A
  • AAAA
  • CERT
  • CNAME
  • DHCID
  • DLV
  • DNAME
  • DNSKEY
  • DS
  • HINFO
  • HIP
  • IPSECKEY
  • KX
  • LOC
  • MX
  • NAPTR
  • NS
  • NSEC
  • NSEC3
  • NSEC3PARAM
  • OPT
  • PTR
  • RRSIG
  • SOA
  • SPF
  • SRV
  • SSHFP
  • TA
  • TALINK
  • TXT

I wrote a basic function to use this API with more ease, you can find it on my GitHub repo:

https://github.com/edemilliere/Misc/blob/master/Get-PublicDnsRecord.ps1

You can load the function without downloading the file with:

Invoke-Expression (Invoke-WebRequest -Uri https://raw.githubusercontent.com/edemilliere/Misc/master/Get-PublicDnsRecord.ps1 | Select-Object -ExpandProperty Content)

You can use it without specifying a node and it will select one randomly from the list available on the API:

Get Public Dns Record Value PowerShell - Function Output

Get Public Dns Record Value PowerShell – Function Output

You can also choose one, the auto-completion will work on this, and on record type too.

Hereunder an example on how to use the function to check some Office 365 DNS prerequisites:

Get Public Dns Record Value PowerShell - Office 365 Exemple

Get Public Dns Record Value PowerShell – Office 365 Example

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.