Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

An AppleScript to look up NetBIOS names Network
When pointing the Finder or Print Center at an SMB (Windows) file share or printer (see this hint), NetBIOS names don't seem to do the trick. Mac OS X wants DNS names or IP addresses. So, a share that you "map" on MS Windows clients as MYSERVERMYSHARE has to get translated to something like smb://myserver.company.com/myshare in order for the Finder to understand it in the Connect to Server box. The problem I've found is that these mappings aren't always obvious.

Fortunately, Jaguar comes with some Samba UNIX tools that can help out with this problem, but they're kind of obscure. After much headache and stumbling through web tutorials, I wrote the following AppleScript to make them easy to use for name/address translation.

Read the rest of the hint for the script...

This script relies on the presence of a WINS server (the NetBIOS equivalent of a DNS server) entry in /private/etc/smb.conf. Mine already had such an entry, but your mileage may vary. When run, the script asks for a NetBIOS name and then attempts to get an associated IP address and DNS name. You can also click "More Info" in the results box to open two stacked Terminal windows with more detailed information (other NetBIOS names associated with the same device, and shares available on the device. Note that the latter may ask for a server password in the Terminal). From there you can copy and paste as needed to construct an SMB pathname that the Finder or the Print Center will understand.

--attempt to read the WINS server from the smb.conf file
set myConfig to do shell script "grep wins /private/etc/smb.conf"
if myConfig = "" then
  display dialog "Couldn't find a WINS server entry in smb.conf" buttons {"Cancel"}
else
  -- grab the IP address of the WINS server
  set AppleScript's text item delimiters to " = "
  set myWINS to get last text item of myConfig
  
  --get the NetBIOs name to lookup
  set theInput to display dialog 
    "Enter the NetBIOS name to look up (in uppercase):" default answer 
    "SERVER" buttons {"Cancel", "OK"} default button "OK"
  
  if button returned of theInput is "OK" then
    
    set theServer to text returned of theInput
    
    -- do a basic lookup and display the result in a dialog box
    set theOutput to do shell script "nmblookup -T -U " & myWINS & " -R " & theServer
    set moreOutput to display dialog theOutput buttons {"More Info", "OK"}
    
    -- open the Terminal to provide a more detailed display if desired
    if button returned of moreOutput is "More Info" then
      tell application "Terminal"
        activate
        -- make room for a second window
        set the position of the front window to {100, 22}
        -- do a detailed lookup of the server's NetBIOS properties
        do script "nmblookup -T -S -U " & myWINS & " -R " & theServer 
          in the front window
        set winHeight to the last item of (get the size of the front window)
        --look up active shares on the server in a new window positioned below the first
        do script "smbclient -L " & theServer
        set the position of the front window to {100, (22 + winHeight)}
      end tell
    end if
  end if
end if
If you don't want to bother with Script Editor, there's a version saved as an application that you can download here.

[robg adds: I haven't tested this one...]
    •    
  • Currently 2.40 / 5
  You rated: 5 / 5 (5 votes cast)
 
[33,301 views]  

An AppleScript to look up NetBIOS names | 15 comments | Create New Account
Click here to return to the 'An AppleScript to look up NetBIOS names' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to look up NetBIOS names
Authored by: Eravau on Mar 28, '03 10:29:28AM

Works like a charm. Wish I'd had this script or known about nmblookup 6 months ago when I was trying to find the IP address of a machine on our network at work that I needed to connect to. Of course, being a Windows-centric corporation, I had to hunt the info myself since all I could get out of the people who wanted me to connect to the machine was the NetBIOS name. Thanks for making this info known.



[ Reply to This | # ]
An AppleScript to look up NetBIOS names
Authored by: DevNull on Apr 02, '03 12:40:57PM

You don't need a WINS server to lookup a NETBIOS name with NMBLOOKUP (although it does speed up things if it is there). NMBLOOKUP will query your subnet if a NETBIOS server is not present. Therefore this hacked version of the script will not work for machines on another subnet. Here is a hacked version of the original script for users in this situation (say if you are in a workgroup without a NETBIOS server).

--get the NetBIOs name to lookup
set theInput to display dialog
"Enter the NetBIOS name to look up (in uppercase):" default answer
"SERVER" buttons {"Cancel", "OK"} default button "OK"

if button returned of theInput is "OK" then

set theServer to text returned of theInput

-- do a basic lookup and display the result in a dialog box
set theOutput to do shell script "nmblookup -T -R " & theServer
set moreOutput to display dialog theOutput buttons {"More Info", "OK"}

-- open the Terminal to provide a more detailed display if desired
if button returned of moreOutput is "More Info" then
tell application "Terminal"
activate
-- make room for a second window
set the position of the front window to {100, 22}
-- do a detailed lookup of the server's NetBIOS properties
do script "nmblookup -T -S -U " & myWINS & " -R " & theServer
in the front window
set winHeight to the last item of (get the size of the front window)
--look up active shares on the server in a new window positioned below the first
do script "smbclient -L " & theServer
set the position of the front window to {100, (22 + winHeight)}
end tell
end if
end if



[ Reply to This | # ]
WINS server lookup
Authored by: Kool on Mar 28, '03 11:56:57AM

Is there a clever way to look up the address of a WINS server in the network without bothering the system administator?



[ Reply to This | # ]
WINS server lookup
Authored by: stevec on Mar 28, '03 12:28:31PM

to answer the "look up a WINS server" question. From any NT/2K/XP system type IPCONFIG /ALL at a command prompt. For 9X PCs use WINIPCFG. This will give you all the IP stats on that PC which should include at least a primary WINS server. Note that if you use active directory you may not have a WINS server, just DNS.

OK my smb.conf is devoid of WINS server entries. Anyone care to post an example so I can avoid the pain of combing the man page for the proper syntax?



[ Reply to This | # ]
proper syntax in /etc/smb.conf
Authored by: jzsimon on Mar 28, '03 04:22:51PM

<stuff>
[global]
<more stuff>

workgroup = <workgroupName>
wins server = <winsServer>
[homes]
<more stuff>
;[public]
; path = /tmp
<more stuff>

But I'd advise using Directory Access to create it for you...



[ Reply to This | # ]
WINS server lookup
Authored by: Thomas Kaiser on Mar 28, '03 12:40:37PM
You can have a look for MASTER BROWSERs, by
    nmblookup -M -
and then use all those machines as a potential WINS server eg. by
    nmblookup -U [WINS server to query] -R [anything]
and search for "wins_srv_died()" messages. Maybe you'll find one that
can answer. This should be a properly acting WINS server.

BTW: In small networks there is no need for WINS at all. Local browsing
should (not ;-) work as expected.

Regards,

Thomas

[ Reply to This | # ]
An AppleScript to look up NetBIOS names
Authored by: iu-macboy on Mar 28, '03 02:41:13PM

Your download link appears to be broken:"Oops!!! File Sharing Error: Missing user argument."

---



[ Reply to This | # ]
Re: Download link
Authored by: xeroply on Mar 28, '03 04:26:15PM
Hmm. It worked when I previewed the submission but it looks like part of it got chopped off.

Try this link

[ Reply to This | # ]
D'oh!
Authored by: xeroply on Mar 28, '03 04:29:03PM

Well the link keeps getting mangled. Sorry 'bout that. Just go to homepage.mac.com/xeroply and click on Downloads.



[ Reply to This | # ]
An AppleScript to look up NetBIOS names
Authored by: krove on Mar 28, '03 02:57:05PM

The WINS server only seems to be present in the /etc/smb.conf file if one has configured SMB setup via the /Applications/Utilities/Directory Access application. To do so, follow these steps:

1. Launch the /Applications/Utilities/Directory Access application
2. Click the lock and provide your Mac OS X administrator password.
3. Click on SMB and then click the "Configure..." button
4. Enter your active directory domain information (if you have one) or workground and then enter the ip address for the WINS server (still have to get this from your sys admin).
5. Click OK and your /etc/smb.conf file should now have that information!



[ Reply to This | # ]
An AppleScript to look up NetBIOS names
Authored by: stevec on Mar 28, '03 04:27:26PM
Cool, thanx! I just knew I was missing something. for those of you just curious, this is what it does to the smb.conf file
[global]
 client code page = 437
 coding system = utf8
 guest account = unknown
 encrypt passwords = yes

  workgroup = sarnoff
  wins server = 130.33.x.x
[homes]
It added only the workgroup and wins server lines

[ Reply to This | # ]
An AppleScript to look up NetBIOS names
Authored by: idiotben on Mar 28, '03 09:19:49PM

this script just errors out "an error of type 1 has occured"

Odd. No matter, I know how to use nmblookup anyway ;-)



[ Reply to This | # ]
script is unfriendly to Terminal
Authored by: jzsimon on Mar 31, '03 11:28:03AM

A small quibble:

There is a problem with the way the above applesccript takes over Terminal. It might look nice to re-arrange the windows and send two commands to two different terminals, but it messes up whatever terminal window layout there was, and if the default window size was made larger, the new window pops up at the level of the Dock.

Worse than that, though, is the use of the frontmost terminal window at all. If the frontmost terminal window is logged into another computer (e.g. via ssh), the command sent to that window make no sense. And if that frontmost terminal window isn't idle, the command doesn't work either.

It would be cleaner to do everything in a new terminal window and let that window pop up in the default location.

IHM0.



[ Reply to This | # ]
An AppleScript to look up NetBIOS names
Authored by: andyinindy on Dec 20, '04 01:12:41PM
For those that are interested, here is an AppleScript that will get IP addresses from netBIOS names. We needed this because we cannot connect using netBIOS names from OS X VNC applications.


tell application "Finder"
	activate
	display dialog "Please enter the NetBIOS name of the computer:" default answer ""
	set myName to the text returned of the result
end tell
--you will need to replace 159.242.130.24 with your own WINS server address
set myIP to (do shell script "nmblookup -U 159.242.130.24 -R " & myName & "| grep '<00>' | awk '{print $1}'")
tell application "Finder"
	display dialog myIP
end tell


[ Reply to This | # ]
Shell alias
Authored by: Lutin on May 08, '07 05:14:23AM
To use from shell:
function ip_from_netbios {
	nmblookup -R "$1" | grep '<00>' | cut -d' ' -f1
}

I found that the Wins server wasn't needed.

[ Reply to This | # ]