示例

新手上路,请多包涵

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

原文由 Maria Kurnosova 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 631
1 个回答

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

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

 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')

原文由 neif 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题