Category Archives: DNS

Problem with DNS name resolution when using System.Net.DNS class

Written by Tao Yang

I recently ran into a problem when writing a PowerShell script to perform DNS Name resolution using .NET class System.Net.DNS (

I noticed when I’m using System.Net.DNS to perform reverse lookup (GetHostByAddress method), even though the PTR record is missing in DNS, it is still able to resolve the name. It looks like this method connects to the host to retrieve its host name.

When the machine is powered off, GetHostByAddress method is unable to resolve the IP address to it’s name (Which is desired result because there is no PTR record in reverse lookup zone):


I then powered on the machine (Jump01), now I get different result. the IP address has been resolved to the host name:


Because of the inconsistent result, I am not able to use System.Net.DNS class (even there are few other methods in this class, but the results are all the same).

What I really need is a way to perform DNS name resolution and provides SAME result as using nslookup. I found several PowerShell community projects, but none of them suits my requirement:



Reason: C# code wrapped inside the PowerShell script. Only works on 32bit PowerShell console.

C# .NET DNS query component:



Reason: Does not perform PTR (reverse) lookup.


Source & Guide:

Reason: It does not perform what it claims to do. I.e. The DnsQueryRequest.Resolve method only takes 4 parameters, not 5 as what instruction says. Also, it does not resolve IP to name. (for example, it does not resolve, but it resolves


Source & Guide:

Reason: this works great and it’s easy to use. can perform reverse lookup using a single PowerShell Cmdlet Get-DNSRecord. However, I need to place the source to %PSModulePath% and import the module in PowerShell. I cannot do this to the production server which I use to run my script.

At the last, I found a freeware called JHSoftware.DnsClient and it solved my problem!


As shown above

1. I first load the dll into Powershell


2. nslookup, make sure the PTR record does not exist

3. use the LookupReverse method from JHSoftware.DNSClient class the perform reverse lookup on (JUMP01). it could not find it and an error was thrown.


4. Modify the PowerShell command, used Try-Catch statement, produced more user friendly output.

Try {[JHSoftware.DNSClient]::LookupReverse(“”)} Catch {“PTR Record not found!”}

5. use same method (LookupReverse) to perform reverse lookup on one of my SCCM server, it successfully returned the FQDN.

This is to do with my DNS record check which is part of my SCCM Health Check script that I posted in previously. I am rewriting the DNS records check in the script as it produces inaccurate result. I have already completed the ability of utilizing PowerShell Remoting to check inboxes backlogs as I mentioned in the previous post. I will post the updated SCCM Health Check script in the next few days.