Search for previous posts

Blog History

10/14/21

Python SMB connection

Simple script to make an SMB connection with Python

import smb

from smb.SMBConnection import SMBConnection

userID = 'username'
password = 'password'
client_machine_name = 'laptop'

server_name = 'fileserver01'
server_ip = 'x.x.x.x'

domain_name = 'domain.local'

conn = SMBConnection(userID, password, client_machine_name, server_name,  
domain=domain_name, use_ntlm_v2=Trueis_direct_tcp=True)

conn.connect(server_ip, 445)

shares = conn.listShares()

for share in shares:
    if not share.isSpecial and share.name not in ['NETLOGON''SYSVOL']:
        sharedfiles = conn.listPath(share.name, '/')
        for sharedfile in sharedfiles:
            print(sharedfile.filename)

conn.close()

References:

[1] https://gist.github.com/joselitosn/e74dbc2812c6479d3678

No comments:

Post a Comment