Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 831
Harvey Kwok Avatar asked Jan 20 '11 18:01

Harvey Kwok


People also ask

How is a NetBIOS name resolved?

Name Resolution Methods The three standard ways of resolving NetBIOS names to IP addresses are through a local broadcast, using the local cache, or by using a NetBIOS name server. With a local broadcast, a broadcast is sent out on the network requesting the IP address of a specific host.

Does Windows 7 use NetBIOS?

In Windows 7, the default NetBIOS setting is to use the NetBIOS setting provided via DHCP. If a Windows 7 computer uses a static IPv4 address, it will automatically use NetBIOS over TCP/IP.


1 Answers

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. :)

like image 53
Tridus Avatar answered Sep 18 '22 17:09

Tridus