[Samba] python: listing samba shares

Ricardo Jorge rvelhote at gmail.com
Sun Aug 16 15:25:18 MDT 2009


> When just launching your code (with provided credentials), I have a segfault. With the credentials code snippet removed, everything > works fine, and I can see the shares listing! But when changing "localhost" to another ip address (a windows machine), it fails:

About the segfault, I don't know why it happens. I found that it
happened (and already reported it) when creds.set_workstation was
omitted. I don't know what it could be in your situation.



Try this code instead. I changed the transport type to ncacn_ip_tcp.
It seems that you didn't need the credentials to do the smbclient
listing so you can also try removing them from there.

try:
        conn = srvsvc.srvsvc('ncacn_ip_tcp:192.168.1.68', credentials=creds)
except Exception, msg:
        print 'boooooo'
        print str(msg)
else:
        ctr = srvsvc.NetShareInfoCtr()
        shares = conn.NetShareEnumAll(u'192.168.11.68', ctr, 0, 0)

        print "\n\n============"
        print "There are " + str(shares[0].ctr.count) + " shares"
        print "============\n"

        for i in range(0, shares[0].ctr.count):
                share_info = info =
conn.NetShareGetInfo(u'192.168.1.68', shares[0].ctr.array[i].name, 2)
                print share_info.name + "\t" + share_info.path + "\t "
+ share_info.comment

        print "\n\n"

>
> I would like to list remote samba shares contents (most of which are windows
> machines), not the local ones. So os.listdir() cannot help here.
>

You're correct, I forgot about that detail :) I couldn't find a
binding for this in the Python library.


More information about the samba mailing list