pysmb 示例 [英] Example of pysmb

查看:51
本文介绍了pysmb 示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能给我一个使用 pysmb 库连接到一些 samba 服务器的例子吗?我读过有class smb.SMBConnection.SMBConnection(用户名、密码、my_name、remote_name、domain=''、use_ntlm_v2=True)但我不知道如何使用它

Could you give me an example of using pysmb library to connect to some samba server? I've read there's class smb.SMBConnection.SMBConnection(username, password, my_name, remote_name, domain='', use_ntlm_v2=True) but i can't figure out how to use it

推荐答案

我最近一直在使用 pysmb 进行网络共享枚举,发现不是那么容易找到好的/完整的示例.我会向您推荐我编写的一个小脚本,用于枚举与 pysmb 的 smb 共享:https://github.com/n3if/scripts/tree/master/smb_enumerator

I have been using pysmb for network shares enumeration lately, and found that it is not so easy to find good / complete examples. I'd refer you to a small script that I wrote for enumerating smb shares with pysmb: https://github.com/n3if/scripts/tree/master/smb_enumerator

为了完整起见,我还在这里发布了完成连接和枚举的代码片段:

For the sake of completeness, also, I post here the code snippet that accomplishes the connection and enumeration:

from smb import SMBConnection

try:
    conn = SMBConnection(username,password,'name',system_name,domain,use_ntlm_v2=True,
                         sign_options=SMBConnection.SIGN_WHEN_SUPPORTED,
                         is_direct_tcp=True) 
    connected = conn.connect(system_name,445)

    try:
        Response = conn.listShares(timeout=30)  # obtain a list of shares
        print('Shares on: ' + system_name)

        for i in range(len(Response)):  # iterate through the list of shares
            print("  Share[",i,"] =", Response[i].name)

            try:
                # list the files on each share
                Response2 = conn.listPath(Response[i].name,'/',timeout=30)
                print('    Files on: ' + system_name + '/' + "  Share[",i,"] =",
                                       Response[i].name)
                for i in range(len(Response2)):
                    print("    File[",i,"] =", Response2[i].filename)
            except:
                print('### can not access the resource')
    except:
        print('### can not list shares')    
except:
    print('### can not access the system')

这篇关于pysmb 示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆