Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
09-20-2013, 01:35 AM
|
#1
|
Member
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269
Rep:
|
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.
|
|
|
09-20-2013, 10:11 AM
|
#2
|
Senior Member
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983
|
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?
|
|
|
09-20-2013, 10:24 AM
|
#3
|
Member
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269
Original Poster
Rep:
|
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?
|
|
|
09-20-2013, 10:58 AM
|
#4
|
Senior Member
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983
|
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.
|
|
|
09-20-2013, 12:53 PM
|
#5
|
Member
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269
Original Poster
Rep:
|
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.
|
|
|
09-20-2013, 02:47 PM
|
#6
|
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:
|
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
|
|
|
09-20-2013, 03:06 PM
|
#7
|
Senior Member
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983
|
Quote:
Originally Posted by ronlau9
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.
|
09-21-2013, 05:57 AM
|
#8
|
Member
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269
Original Poster
Rep:
|
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.
|
|
|
09-21-2013, 08:57 AM
|
#9
|
Moderator
Registered: Aug 2002
Posts: 26,358
|
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.
|
09-21-2013, 02:19 PM
|
#10
|
Member
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269
Original Poster
Rep:
|
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
|
|
|
09-21-2013, 04:00 PM
|
#11
|
Moderator
Registered: Aug 2002
Posts: 26,358
|
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.
|
09-21-2013, 06:00 PM
|
#12
|
Member
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269
Original Poster
Rep:
|
Quote:
Originally Posted by michaelk
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
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
|
|
|
All times are GMT -5. The time now is 01:47 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|