LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 09-20-2013, 01:35 AM   #1
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269

Rep: Reputation: 25
NAS Discovery - how?


Greetings

How can I search and discover NAS devices attached to my LAN from a shell/bash? I'm trying to write a bash script for NAS discovery, but I am unsure what commands to use. It is supposed to enumerate the local network shares.
 
Old 09-20-2013, 10:11 AM   #2
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
what exactly are you looking for? are you looking for a brand new NAS plugged fresh into a DHCP network to identify its IP?

are you looking for an already configured NAS with a static IP?

what?
 
Old 09-20-2013, 10:24 AM   #3
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269

Original Poster
Rep: Reputation: 25
Either one. I need a list of local shares where a user can select a share in a web-gui (possibly provide authentication), and have the server connect/mount that share to a specific folder. I don't own a NAS, so I have no idea how to discover them. I mean what protocols do they use to announce their presence? CIFS? NFS? UPNP?
 
Old 09-20-2013, 10:58 AM   #4
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
it all depends on the brand and how they are configured. could be cifs, could be nfs, could be afs or even ftp.

you would detect a share like you would any other kind of share detection. each type has its own method of detection. nfs for example uses exports -a.

so yes what you are wanting to do perform is possible, but you need to narrow down, or expand exactly what you are looking for.

sounds like you need to start writing the script then when you need additional help post back to these forums with detailed questions. there are plenty of great script masters around here willing to help.
 
Old 09-20-2013, 12:53 PM   #5
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269

Original Poster
Rep: Reputation: 25
I'm looking to implement support for the most common consumer-grade NAS' - the ones you can get from shelves or internet stores? Most average users have Windows on their machines, so I assume the protocol of choice would be Samba/CIFS.

EDIT: According to some websites the two most common protocols are NFS and CIFS. Good, this is one part of information I was looking for. Now how to discover which machines on the network offer these services. I could use nmap, but that would be an overkill.

EDIT2: You mentioned exports for NFS and samba seems to have a tool called smbtree. I'll play with these a bit.

Last edited by displace; 09-20-2013 at 01:04 PM.
 
Old 09-20-2013, 02:47 PM   #6
ronlau9
Senior Member
 
Registered: Dec 2007
Location: In front of my LINUX OR MAC BOX
Distribution: Mandriva 2009 X86_64 suse 11.3 X86_64 Centos X86_64 Debian X86_64 Linux MInt 86_64 OS X
Posts: 2,369

Rep: Reputation: Disabled
I do not know what you exactly like to do .
It does not matter if use the linux box , Mac BOx or the windows box .
Typing in firefox find.synology.com it connects to my NAS and it give two options sign as a user or as admin
Signing in as admin I can do anything with NAS
 
Old 09-20-2013, 03:06 PM   #7
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Quote:
Originally Posted by ronlau9 View Post
I do not know what you exactly like to do .
It does not matter if use the linux box , Mac BOx or the windows box .
Typing in firefox find.synology.com it connects to my NAS and it give two options sign as a user or as admin
Signing in as admin I can do anything with NAS
yes each manufacture typically will have something like that, or they will have tools you can run, etc...

also keep in mind, there is zero share by default on many SoHo NAS devices. they are typically configured for DHCP, then require either a web interface access and very few have CLI interface access for configuration.

typically its all web based for configuration. setting user/pw, setting types of shares, setting permissions, etc...

if you are looking to discover a new NAS randomly plugged into your LAN, then configure via same script, i dont know if you will pull that off with all SoHo types of NAS devices just as most dont have CLI interfaces for configuration.

if you are just attempting to detect a new NAS connected to a LAN, then you might look into nmap. i have used that many times to locate a NAS as they typically will report their manufacture and type.
 
1 members found this post helpful.
Old 09-21-2013, 05:57 AM   #8
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269

Original Poster
Rep: Reputation: 25
Maybe I forgot to mention that I'm doing this on a headless system. So no firefox, file managers or gui tools. There's gonna be a web interface in php where a user can connect, and view a list of NAS devices. Thanks for pointing that out about unconfigured NAS devices, but I'm only interested in configured devices that have some existing shares defined.

I wrote this python script that seems to detect most of the CIFS shares.
Code:
import sys, re, json
import subprocess

try:
	popen = subprocess.Popen("smbtree -N -d 0", shell=True, stdout=subprocess.PIPE)
	ret = popen.wait()
except:
	sys.exit(1)

out = popen.stdout.read()
output = out.split("\n")
results = {}
workgroup = ""
server = "//"

for line in output:
	r = re.match("^\s\s(\S+)\s+(.*)$", line)
	if r is not None:
		share = r.group(1)
		desc = r.group(2).strip()
		results[workgroup][server][share] = desc
		continue
	
	r = re.match("^\s(\S+)\s+(.*)$", line)
	if r is not None:
		server = r.group(1)
		desc = r.group(2).strip()
		results[workgroup][server] = {'desc': desc}
		continue
	
	r = re.match("^\S+", line)
	if r is not None:
		workgroup = r.group(0)
		results[workgroup] = {}
		continue

print json.dumps(results)
sys.exit(0)
I'll have to play around with the exports and see if I can get a list of NFS shares.

Edit: I wrote a simpler python script that only shows visible/public CIFS shares.
Code:
import sys
import re
import json
import subprocess

try:
	popen = subprocess.Popen("smbtree -N -d 0", shell=True, stdout=subprocess.PIPE)
	ret = popen.wait()
	if ret != 0:
		sys.exit(ret)
	out = popen.stdout.read()
except:
	sys.exit(1)

results = []
output = out.split("\n")
for line in output:
	r = re.match("^\t\t(\\\\\S+[^$\s])\s+(.*)$", line)
	if r is not None:
		share = r.group(1)
		desc = r.group(2).strip()
		results.append({share : desc})
		continue
print json.dumps(results)
sys.exit(0)

Last edited by displace; 09-21-2013 at 08:43 AM.
 
Old 09-21-2013, 08:57 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,358

Rep: Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149
The only utility to see NFS shares that I know about is showmount. It is per server i.e. it can not browse a network.
 
1 members found this post helpful.
Old 09-21-2013, 02:19 PM   #10
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269

Original Poster
Rep: Reputation: 25
Thank you.
Do you perhaps know how to discover local FTP shares (without using a port scanner like nmap)?
I'm hoping for a ftp-equivalent of the "smbtree" and "showmount" commands.

~dis
 
Old 09-21-2013, 04:00 PM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,358

Rep: Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149Reputation: 6149
No browsing tool. You could use cURL to test for a FTP server. However, since you posted that the NASs would already be configured I would expect that the IP address and the top level shares/protocols would already be defined. By the way smbtree will find all cifs shares regardless if they are on a NAS or other PC with sharing enabled.
 
1 members found this post helpful.
Old 09-21-2013, 06:00 PM   #12
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269

Original Poster
Rep: Reputation: 25
Quote:
Originally Posted by michaelk View Post
No browsing tool. You could use cURL to test for a FTP server. However, since you posted that the NASs would already be configured I would expect that the IP address and the top level shares/protocols would already be defined.
Erm the point is to help the user so that he won't have to remember and manually enter hostname or the IP address of the NAS - just provide a list instead. Though manual configuration is still an option.

Quote:
Originally Posted by michaelk View Post
By the way smbtree will find all cifs shares regardless if they are on a NAS or other PC with sharing enabled.
Correct. This is exactly what I'm looking for. A user can easily configure a PC to act like a NAS. I mean I've done it myself ages ago.


Alright then. I believe I have all the information I was looking for. I recall nmap had some interesting lua scripts to scan FTP servers. I'll see if I can adapt them for my use or at least write something similar and simpler.

~dis
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
reliable centos nas server with raid or nas boxes which is better ? Gil@LQ Linux - Server 9 09-10-2015 06:13 AM
automatically backup folder on Free NAS computer to another Free NAS computer tom treadway Linux - Newbie 1 01-26-2011 08:28 PM
Buffalo NAS - how do we get files on NAS syncing with Windows Sync? bykerbob Linux - Newbie 0 10-21-2008 09:59 PM
ip discovery teknofreak Linux - Networking 2 05-31-2005 10:23 AM
What's in Discovery that's not in Download 10? craigl Mandriva 2 04-27-2004 05:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 01:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration