如何使用 pywinrm 在 Windows 台机器上收集文件?

How to collect files on Windows machines with pywinrm?

如何在Windows台机器上收集文件?

pywinrm 连接密码被拒绝,但密码正确且连接端口正在侦听

脚本:

import winrm

s = winrm.Session('192.168.9.102', auth=('domain\username', 'password'))
r = s.run_cmd('ipconfig', ['/all'])

print(r.status_code)

print(r.std_out)

输出:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/winrm/transport.py", line 329, in _send_message_request
    response.raise_for_status()
  File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error:  for url: http://192.168.9.102:5985/wsman

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "get.py", line 4, in <module>
    r = s.run_cmd('ipconfig', ['/all'])
  File "/usr/local/lib/python3.7/site-packages/winrm/__init__.py", line 39, in run_cmd
    shell_id = self.protocol.open_shell()
  File "/usr/local/lib/python3.7/site-packages/winrm/protocol.py", line 166, in open_shell
    res = self.send_message(xmltodict.unparse(req))
  File "/usr/local/lib/python3.7/site-packages/winrm/protocol.py", line 243, in send_message
    resp = self.transport.send_message(message)
  File "/usr/local/lib/python3.7/site-packages/winrm/transport.py", line 323, in send_message
    response = self._send_message_request(prepared_request, message)
  File "/usr/local/lib/python3.7/site-packages/winrm/transport.py", line 333, in _send_message_request
    raise InvalidCredentialsError("the specified credentials were rejected by the server")
winrm.exceptions.InvalidCredentialsError: the specified credentials were rejected by the server

telnet 192.168.9.102 5985

Trying 192.168.9.102...
Connected to 192.168.9.102.
Escape character is '^]'.
^CConnection closed by foreign host.

根据您的服务器配置,您是否尝试过使用其他身份验证传输(如 ntlm):

winrm.Session('192.168.9.102', auth=('username@domain', 'password'), transport='ntlm')