Learning Python Network Programming

(Sean Pound) #1

Interacting with Remote Systems


SERVER_PORT = 445
SERVER_SHARE_NAME = 'Share'
SHARED_FILE_PATH = '/test.rtf'

if __name__ == '__main__':

smb_connection = SMBConnection(SAMBA_USER_ID, PASSWORD,
CLIENT_MACHINE_NAME, SAMBA_SERVER_NAME, use_ntlm_v2 = True,
domain='WORKGROUP', is_direct_tcp=True)
assert smb_connection.smb_connectionect(SERVER_IP, SERVER_PORT
= 445)
shares = smb_connection.listShares()

for share in shares:
print share.name

files = smb_connection.listPath(share.name, '/')
for file in files:
print file.filename

file_obj = tempfile.NamedTemporaryFile()
file_attributes, filesize =
smb_connection.retrieveFile(SERVER_SHARE_NAME,
SHARED_FILE_PATH, file_obj)

# Retrieved file contents are inside file_obj
file_obj.close()

Inspecting SAMBA packets


If we capture the SMABA packets on port 445 , then we can see how the Windows
Server communicates with the Linux SAMBA client over the CIFS protocol.
In the following two screenshots, a detailed communication between the client
and the server, has been presented. The connection setup has been shown in the
following screenshot:

Free download pdf