• 启用 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%15\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'

最新文章

  1. 在java中如何用键盘输入一个数,字符,字符串
  2. 【Alpha版本】十天冲刺集结令
  3. ASP.NET 5探险(6):升级ASP.NET 5到beta6
  4. css文字截取
  5. 链接器工具错误 LNK2011
  6. Qt之遍历文件夹(经典详解)
  7. 极度郁闷的错误调试——ajax jquery
  8. 六度分离(floyd算法+dijskra+SPFA)
  9. node.js实践第二天
  10. c语言,变长数组
  11. 4.Nginx的URL重写应用
  12. WPF自定义Window样式(2)
  13. CF 2015 ICL, Finals, Div. 1 J. Ceizenpok’s formula [Lucas定理]
  14. mysql全局权限账户%登录不上ERROR 1045 (28000): Access denied for user 'mhz'@'localhost' (using password: YES)
  15. CentOS 7上安装Pure-FTPd
  16. centos7安装rabbitmq 总结
  17. 详解如何进行第三方App接入微信登录
  18. urllib — URL handling modules
  19. Entity Framework 6.1.0 Tools for Visual Studio 2012 & 2013
  20. Centos7+Mysql80安装+远程链接开启

热门文章

  1. SpringMVC中@RequestBody接收前端传来的多个参数
  2. Java8——方法引用
  3. 测试人员应该掌握的oracle知识体系
  4. T2 监考老师 题解
  5. 记录一次JSON数据处理(省市区数据)
  6. 10个Vue开发技巧助力成为更好的工程师·二
  7. ISE第三方编辑器的使用
  8. DJANGO-天天生鲜项目从0到1-011-订单-订单提交和创建
  9. 【转载】基于dom的一些前端漏洞
  10. laravel报错1071 Specified key was too long; max key length is 1000 bytes