
def openshares():
    '''
    @description: Uses smbclient to find open SMB shares on a specified host. Usage: ./Intersect.py --openshares 192.168.1.4
    @author: ohdae [bindshell@live.com]
    @short: find open SMB shares
    '''
    ipaddr = sys.argv[2]

    if whereis('smbclient') is None:
        print("[!] SMBClient cannot be found on this system!")
        sys.exit()

    else:
        print("[+] Enumerating open shares....\n")
        log_msg("\n\n [ SMB Shares Module executed ]")
        log_msg("\n Start Time: %s" % logtime)

        os.popen("/usr/bin/smbclient -L %s -N" % ipaddr)

        getdisks = os.popen(r'/usr/bin/smbclient -L %s -N 2>/dev/null| grep " Disk " | sed -e "s/ Disk .*//" | sed -e "s/^[ \t]*//"' % ipaddr)
        disks = getdisks.readlines()
        disks = filter(None, disks)
        disks = [d.strip() for d in disks]
        getdisks.close()

        for disk in disks:
            proc = Popen('/usr/bin/smbclient //%s/"%s" -N -c "dir;exit" 2>/dev/null'%(ipaddr,disk),
                        shell=True,
                        stdout=PIPE,
                        )
            output = proc.communicate()[0]
            print("[+] Contents of %s " % disk)
            print output

