Below is the file 'get.py' from this revision. You can also download the file.
#!/usr/bin/env python # connects to a windows box, produces a list of shares and # then lets you connect to them # useful for security scanning for open shares import sys import os import pipes import popen2 import string from goatpy import smbwrapper def retrieve_share(share): cmd = smbwrapper.build_basic_smbclient(target, workgroup) + ' ' + pipes.quote('//%s/%s' % (node, share)) print print "Executing:", cmd os.system(cmd) def print_share_menu(): print print "IP address:", target print "Node:", node print "Workgroup:", workgroup print for i, share in enumerate(shares): print "%2d." % i, share print print "Select share to connect to: ", share_id = sys.stdin.readline() try: i = int(share_id) retrieve_share(shares[i]) except: pass if __name__ == "__main__": if len(sys.argv) == 2: target = sys.argv[1] node, workgroup = smbwrapper.netbios_lookup(target) if not node or not workgroup: print "Netbios lookup failed." shares = map(lambda x: x[0], smbwrapper.list_shared_resources(target, node, workgroup)) shares.sort() while True: print_share_menu() elif len(sys.argv) == 3: target = sys.argv[1] node, workgroup = smbwrapper.netbios_lookup(target) retrieve_share(sys.argv[2]) else: sys.stderr.write("usage: %s <ip> [share]\n" % (sys.argv[0])) sys.exit(1)