Harvey Kwok
Harvey Kwok

Reputation: 11873

Resolve NetBIOS name on Windows 7

According to this link, NetBIOS is no longer supported starting from Windwos Vista. Sure enough, I can no longer see any NetBIOS name from the network properties.

However, when I am writing codes on my Windows 7, I still encounter NetBIOS names in many places. For example

  1. I can still use "MYDOMAIN\Harvey" to logon my machine, where I believe MYDOMAIN is a NetBIOS name.
  2. The environment variables COMPUTERNAME and USERDOMAIN are still NetBIOS names. I am expecting to see a DNS names here
  3. My SQL Server instance names coming up from my SQL Server Management Studio is still something like MYMACHINE\Instance1.

I am guessing Microsoft still maintains some pieces of it for backward compatibility. I want to understand how Windows 7 going to resolve the NetBIOS name to an IP address. I found this article explaining how the NetBIOS name resolution works but I am afraid this is no longer true in Windows 7. At least there is no WINS server for me.

My last question is how do I do the NetBIOS name resolution programmatically, preferrably in C#. I am okay to use PInvoke.

UDAPTE

Tridus was right. I can use System.Net.Dns.GetHostAddresses("hostname") to resolve NetBIOS name. I used reflector to see what's happening under the hood. It is calling gethostbyname() from ws2_32.dll

Here, it explains the gethostbyname() will do NetBIOS name resolution.

  1. Check the local host name for a matching name.
  2. Check the Hosts file for a matching name entry.
  3. If a DNS server is configured, query it.
  4. If no match is found, attempt NetBIOS name-resolution.

About the mystery of NetBIOS not supported in this link, I think it just means the API is not supported. People in ServerFault think that NetBIOS is still supported in Windows 7.

Upvotes: 6

Views: 9895

Answers (1)

Tridus
Tridus

Reputation: 5081

NetBIOS itself as the old protocol might not be supported, but SMB/CIFS still is and that's why \hostname for filesharing and such still works.

As for how to resolve a name, I was able to do this:

System.Net.Dns.GetHostAddresses("hostname")

I'm on a domain so it may be simply appending a DNS suffix and doing a DNS lookup, but it worked for me. Give it a try. :)

Upvotes: 5

Related Questions