Saturday, February 4, 2012

How to Determine the Master Browser in a Windows Workgroup

Hello there! If you are new here, you might want to subscribe to the RSS feed to receive updates.
NetworkHere’s a little problem that drove me crazy: How do you determine the Master Browser in a Windows Workgroup?
First of all, lemme explain a bit about how a workgroup works. When you have a LAN set up running Windows machines, each machine can see all the others in Network Neighborhood (or just “Network” in Vista). If you want to see the files on another machine, you just go to Network Neighborhood, click, et voila!
The other method you can use is to open Windows Explorer (keyboard shortcut: Win-E) and in the location/address bar, type:
\\COMPUTER-NAME
So, if you want to go to the computer called BALTHAZAR, you’d type:
\\BALTHAZAR
And hit enter. This is handy to know if Network Neighborhood is not working. And a grumpy Network Neighborhood is exactly the reason why sometimes, you need to find out which computer is the Master Browser.

On a local area network (LAN), each computer “talks” to the others. Each computer has an IP address, like 192.168.0.27, and also a name. The name is what you call your computer so you and your friends don’t have to remember the IP address. In our example above, the computer name is BALTHAZAR, but the IP address might be 192.168.0.27. Fabulous.
So, what happens is that each computer on the LAN must talk to the others. Since we’re only dealing with a workgroup, and there is no domain server, there is no computer to keep track of what machines are active on the network. This is where the Master Browser schtick comes into play. What happens is that all the computers on your LAN hold an “election”. This election depends on a number of factors, but for the purposes of this discussion, we just have to know that all the computers get together and vote on who will be the Master Browser on the LAN. Once a computer is elected, it will keep track of what machines are connected to the LAN by more or less sending messages to say, “Yo! You still there?”
Of course, you may ask: What happens when the computer that is the Master Browser gets shut down when, say, I go to bed? In that case, you will find that your Network Neighborhood may not work so well. At that point, all the computers on the LAN get together again and they hold another election. As I understand it, there are one or more “Backup Master Browsers” waiting in the wings, but we’ll ignore that for now.
Now, what happens when you have Network Neighborhood turning up blank on you sporadically, or possibly missing several of the computers on your LAN from time to time? Well, in that case, you need to determine who is the Master Browser so that you can narrow down the problem to one computer and see if maybe you need an updated ethernet driver, or there are firewall problems, or whatever.
The “fun” way of doing this is with DOS commands. Here’s how you’d do it:
  1. Open up a command prompt
  2. Type net view and hit enter
  3. Look at the list of computer names. These are the computers on your LAN. Note that the format is \\COMPUTER-NAME like I talked about above.
  4. For each name in the list, type the following command: nbtstat -a COMPUTER-NAME
One of the results from the nbtstat commands will show a row with “_MSBROWSE_” in it. That means that this computer is the Master Browser.
Wasn’t that fun?
No, it wasn’t.
So, I wrote a little script in Ruby to do this for you. I needed to in order to troubleshoot a networking problem on one machine on my LAN, and I didn’t want to type 10-20 commands every time. But as long as I was writing it, I figured I would jack it up a bit. Here’s what it does:
  • net view net view /domain to determine the list of workgroup names
  • net view /domain:[WORKGROUP] to determine the list of puter names for each [WORKGROUP]
  • extracts the individual computer names and sticks them in an array
  • iterates through the array and calls ping -n 1 -4 COMPUTER-NAME on each computer name (we only want to display IPv4 addresses, hence the “-4″ switch)
  • iterates through the array of IP addresses and calls nbtstat -A IP-ADDRESS (the “-A” means “I’m giving you an IP address instead of a computer name”. This is a more reliable way of doing things.)
  • After each call to nbtstat, it not only checks for the _MSBROWSE_ string, but it also records the MAC address of the network adapter in the remote computer.
  • iterates through all the data and displays a nicely formatted table, like so:
Scanning LAN...

BERT            192.168.0.102   00-18-C0-42-A3-B2   CHEESE
BIGBUBBALOU     192.168.0.103   00-26-32-1F-72-ED   WORKGROUP
RHINOX          192.168.0.101   00-00-00-00-00-00   WORKGROUP   MASTER
Q               192.168.0.100   00-28-F6-68-F5-48   WORKGROUP
RADDAR          192.168.0.105   00-02-0D-74-FC-33   CHEESE
ANGELINA        192.168.0.106   00-B0-7E-C3-F7-A4   CHEESE
MOP             192.168.0.104   00-1B-8C-56-01-52   CHEESE      MASTER
AI              192.168.0.107   00-6A-83-6B-A0-83   WORKGROUP

Press any key to exit...
I wrote this little script in Ruby because it was fast and easy. But I didn’t want to have to call it from a command prompt with ruby all the time, and I wanted others to be able to use it without having to install Ruby on their own computers. So, I compiled it into a self-contained executable using RubyScript2Exe, and I added a pretty icon with Resource Hacker. Now my nifty little 2kB script is a lovely 1.5MB executable. Well, ya know… You can’t have everything. It may be bloated, but at least it works!
You can run it from the command line, or from Windows. It’s best to put the file in your Windows directory. It won’t run properly unless it’s on your boot drive (usually C:). If plopped into the Windows directory itself, it will be executable from any drive or directory on your computer. Anyway, if you run it from Windows, it will just open up a command prompt window and pause before closing it so you can see the results. On my machine, it’s nice and speedy.
Oh, and one last note: it might take 30 seconds or so to scan your LAN. The more machines you have, the more work it was to do.
So, now you have a lovely tool to determine the IP address, MAC address, name, and Master Browser status of all the computers on your LAN.
UPDATE (8 June 2009): My little LANscanner program has been updated to version 1.1. It now supports the x64 flavor of Windows XP, Vista, and 7. Be sure to read the included .TXT file for install instructions!
UPDATE (27 February 2010): LANscanner has been updated to version 1.2. New in this release is the display of the workgroup for each computer, as well as formatting improvements that should make the output easier to read even with long computer/workgroup names.
UPDATE (20 March 2010): LANscanner has been updated to version 1.3. This release is mostly a bug fix for 1.2. In the older version, the only workgroup reported was the one your puter was on. Oops! That didn’t make the feature very useful. Now LANscanner will first scan for all available workgroups, and accurately report all machines on all workgroups, including which puter is the Master Browser for each workgroup. I also optimized some code here and there for good measure.

Download

0 comments:

Post a Comment