- 开启 WinRM 远程服务:
winrm quickconfig
-
很多人学习python,不知道从何练起。
很多人学习python ,把握了基础英语的语法之后,不知道在哪儿找寻实例入门。
许多早已做实例的人,却不知道如何去学习更为深奥的专业知识 。
那麼对于这三类人 ,我给大伙儿出示一个好的学习服务平台,免费领教程视频,电子书 ,及其课程内容的源码!
QQ群:1097524789 -
查询 WinRM 服务项目监视情况:
winrm e winrm/config/listener
C:\Windows\system32>winrm e winrm/config/listener Listener [Source="GPO"] Address = * Transport = HTTP Port = 5985 Hostname Enabled = true URLPrefix = wsman CertificateThumbprint ListeningOn = 127.0.0.1, 169.254.52.7, xx.xx.xx.xx, ::1, fe80::3989:dd91:e6b3:6f41%15, fe80::fd01:a9fd:c410:3407%12
-
容许应用 Basic 验证方法:
winrm set winrm/config/service/auth @{Basic="true"}
winrm set winrm/config/service/auth @{Basic="true"} Auth Basic = true [Source="GPO"] Kerberos = true Negotiate = true Certificate = false CredSSP = false CbtHardeningLevel = Relaxed
-
容许 WinRM 应用非数据加密的联接:
winrm set winrm/config/service @{AllowUnencrypted="true"}
方法二:bat 脚本制作
call winrm quickconfig -quiet
call winrm set winrm/config/service/auth @{Basic="true"}
call winrm set winrm/config/service @{AllowUnencrypted="true"}
方法三:组策略
精准定位到 计算机配置 -> 对策 -> 管理方法模版 -> Windows 部件 -> Windows 远程访问(WinRM) -> WinRM 服务项目 。
开启 容许根据 WinRM 开展远程服务器管理方法 、 容许基础身份认证 、 容许未数据加密通讯 。
提议另外开启服务项目与服务器防火墙对策:
计算机配置-> 对策 -> Windows 设定 -> 安全策略 -> 服务程序 -> Windows Remote Management (WS-Management) ,起动方式为全自动 。
计算机配置-> 对策 -> Windows 设定 -> 安全策略 -> 高級安全性 Windows 服务器防火墙 -> 高級安全性 Windows 服务器防火墙 - XXX -> 入站标准 ,对外开放 5985(HTTP)和 5986(HTTPS)端口号。
二 、Python 应用 pywinrm 联接 WinRM 服务项目
安裝 pywinrm 库: pip install pywinrm
实行 cmd 指令:
>>> import winrm
>>> session = winrm.Session('xx.xx.xx.xx', auth=('Administrator', 'admin_password'))
>>> cmd = session.run_cmd('ipconfig')
>>> cmd.std_out
b'\r\nWindows IP Configuration\r\n\r\n\r\nEthernet adapter \xd2\xd4\xcc\xab\xcd\xf8:\r\n\r\n Connection-specific DNS Suffix . : example.com\r\n Link-local IPv6 Address . . . . . : fe80::3989:dd91:e6b3:6f41\r\n IPv4 Address. . . . . . . . . . . : xx.xx.xx.xx\r\n Subnet Mask . . . . . . . . . . . : 255.255.255.0\r\n Default Gateway . . . . . . . . . : 172.20.23.254\r\n\r\nEthernet adapter \xd2\xd4\xcc\xab\xcd\xf8 2:\r\n\r\n Media State . . . . . . . . . . . : Media disconnected\r\n Connection-specific DNS Suffix . : \r\n'
实行 Powershell 指令:
>>> import winrm
>>> session = winrm.Session('xx.xx.xx.xx', auth=('Administrator', 'admin_password'))
>>> ps = session.run_ps('Get-Disk')
>>> ps.std_out
b'\r\nNumber Friendly Name Serial Number HealthStatus OperationalStatus Total Size Partition \r\n Style \r\n------ ------------- ------------- ------------ ----------------- ---------- ----------\r\n0 ST500DM002... Z3TFS1S3 Healthy Online 465.76 GB MBR \r\n\r\n\r\n'