I'm trying to write a script that will go to a host and list all of its shares.

So far, in my searching, it seems that I need to include a top level share name.

For example:

os.listdir('\\\\1.2.3.4\\')

doesn't seem to work, but

os.listdir('\\\\1.2.3.4\\share\\')

will work.

As a bit of a work-around, I was thinking of first running "net view" and then taking the output from that to input the share name. The only problem I have is I'm not sure how to handle the net view output.

Share name    Type  Used as  Comment

--------------------------------------------------------------
Data          Disk
Data2         Disk
My Docs       Disk
Users         Disk
The command completed successfully.

I thought of using REGEX to look for the lines that contain the work "Disk", but I don't know how to separate the string at that point to get only the share name.

Any tips would be appreciated, or if you know of a better way I can accomplish this, I'm open to suggestions.

Thanks.

This way you can find those names, just replace your action in place of print.

inp="""Share name    Type  Used as  Comment

--------------------------------------------------------------
Data          Disk
Data2         Disk
My Docs       Disk
Users         Disk
The command completed successfully."""

for line in inp.splitlines():
    if line[14:18]=='Disk': print line[0:13].rstrip()

"""Output:
Data         
Data2        
My Docs      
Users        
"""
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.