Listing available smb shares on a network through the command line in linux
Solution 1:
This command is a very little known secret of Samba. It returns IP adresses of all Samba servers in one's own broadcast domain:
nmblookup __SAMBA__
This one returns a list of all NetBIOS names and their aliases of all Samba servers in the neighbourhood (it does a 'node status query'):
nmblookup -S __SAMBA__
This one returns a list of all IP adresses of SMB servers (that is, Linux+Unix/Samba or Windows) in the neighbourhood:
nmblookup '*'
Finally, all NetBIOS names and their aliases of all SMB servers (Linux+Unix/Samba or Windows):
nmblookup -S '*'
The command given in the other answer nmblookup -S WORKGROUP
does NOT return all Samba or all SMB servers from the neighbourhood. Instead, it returns all servers' NetBIOS names who happen to be members of a workgroup named 'WORKGROUP'. The results are independent of the servers' OS (wether that is Windows, or wether that is Linux/Samba) -- and it is a well known fact that sometimes lots of Windows member server are part of a Samba-controlled domain or workgroup. [Yes, it happens that Samba's default workgroup name is 'WORKGROUP'... but so what??]. -- But the question was 'How do I get to know all SMB (Samba?!?) servers in my network neighbourhood?'
Solution 2:
nmblookup -S WORKGROUP
from the: https://web.archive.org/web/20101121043732/http://brneurosci.org/linuxsetup38b.html
Solution 3:
On my network - as of this writing (things do change) - smbtree is my preferred solution. It asks for your password (meaning your Samba password), and then it gives a nicely detailed list that includes netbios name, available shares, and the share description.
nmblookup, on the other hand, does not list all the available shares on my network. I do not know why it does not, but it doesn't.
From the smbtree man page:
smbtree is a smb browser program in text mode. It is similar to the "Network Neighborhood" found on Windows computers. It prints a tree with all the known domains, the servers in those domains and the shares on the servers.
The nmblookup command does have more switches and options. The nmblookup man page: nmblookup man page
Noted for posterity - as these answers do stick around - and as I said, I find that smbtree would be a better answer to the OP on my network.
Solution 4:
a better way, more fiendly printed, is to use smbtree.
$ smbtree
Enter user01's password: DOMAIN_A
\\FREEBOX_SERVER Freebox Server
\\FREEBOX_SERVER\IPC$ IPC Service (Freebox Server)
\\FREEBOX_SERVER\Disque dur AutoShare of fbxhdiskd partition 2
Solution 5:
In samba version 4, nmblookup '*'
no longer works; it only gives the local server. It used to work in samba version 3.
Now, you have to use nmblookup WORKGROUP
, which as Kurt mentioned, only returns servers in workgroup WORKGROUP
.