https://learn.microsoft.com/en-us/windows/win32/winrm/install...
WinRM(Windows Remote Management)是微软开发的一种远程管理协议,基于 WS-Management(Web Services for Management)标准。它允许用户远程执行命令、访问WMI(Windows Management Instrumentation)数据,或者运行 PowerShell 脚本,用于远程配置和自动化管理 Windows 系统。在 Windows Server 2008 及更高版本中,WinRM 服务默认自动启动,默认情况下,未配置任何 WinRM 侦听器。即使 WinRM 服务正在运行,也无法接收或发送请求数据的 WS-Management 协议消息
winrm 服务系统已经默认安装,但是需要配置
快速配置
winrm quickconfig
或者
winrm qc
执行
winrm enumerate winrm/config/listener
可以查看监听状态
可以看到默认监听的端口是 5985,默认是 http 协议
默认不可以未加密访问,访问会报错
比如
the specified credentials were rejected by the server
在 cmd 执行下面的命令开启 http 和 basic 访问
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
使用 python 测试
import winrm
ip = "you ip"
username = "Administrator"
password = "password"
s = winrm.Session(ip, auth=(username, password))
r = s.run_cmd('ipconfig', ['/all'])
print(r.status_code)
print(r.std_out)
使用 http 和管理员账号密码访问
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。