一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - Python Tricks 使用 pywinrm 遠程控制 Windows 主機的方法

Python Tricks 使用 pywinrm 遠程控制 Windows 主機的方法

2020-07-21 17:34StarryLand Python

這篇文章主要介紹了Python Tricks 使用 pywinrm 遠程控制 Windows 主機的方法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

啟用 WinRM 遠程服務: winrm quickconfig

查看 WinRM 服務監聽狀態: winrm e winrm/config/listener

?
1
2
3
4
5
6
7
8
9
10
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"}

?
1
2
3
4
5
6
7
8
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 腳本

?
1
2
3
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 進行遠程服務器管理允許基本身份驗證允許未加密通信

Python Tricks 使用 pywinrm 遠程控制 Windows 主機的方法

建議同時啟用服務與防火墻策略:

計算機配置-> 策略 -> Windows 設置 -> 安全設置 -> 系統服務 -> Windows Remote Management (WS-Management) ,啟動模式為自動。

計算機配置-> 策略 -> Windows 設置 -> 安全設置 -> 高級安全 Windows 防火墻 -> 高級安全 Windows 防火墻 - XXX -> 入站規則 ,開放 5985(HTTP)和 5986(HTTPS)端口。

二、Python 使用 pywinrm 連接 WinRM 服務

安裝 pywinrm 庫: pip install pywinrm

執行 cmd 命令:

?
1
2
3
4
5
>>> 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 命令:

?
1
2
3
4
5
>>> 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'

到此這篇關于Python Tricks 使用 pywinrm 遠程控制 Windows 主機的方法的文章就介紹到這了,更多相關Python Tricks遠程控制 Windows 主機內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!

原文鏈接:https://rollingstarky.github.io/2020/07/20/python-tricks-remote-control-windows-machines-with-pywinrm/

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲国产精品第一页 | 国产成人精品实拍在线 | 日韩精品一区二三区中文 | tube8老师| 国色天香社区视频在线观看免费完整版 | 亚洲免费在线观看 | 欧美一级欧美三级在线 | 久久久久琪琪精品色 | 欧美成人免费一区在线播放 | jj视频免费 | 欧美生活一级片 | 甜性涩爱 | 513热点网 | 好姑娘在线完整版视频 | 青青热久免费精品视频精品 | 国产日韩欧美一区 | 精品日韩二区三区精品视频 | 色多多视频在线 | 女子张腿让男人桶免费 | 国产亚洲精品一区久久 | 天天综合网网欲色 | 我把寡妇日出水好爽 | 第一次破学生处破 | chinesespanking网站 | free性泰国女人hd | 亚洲国产精品综合福利专区 | 国产精品视频一区二区三区不卡 | 免费xxxxx大片在线观看影视 | 成人免费片 | 国产hd老头老太婆 | www.男人| 五月一区二区久久综合天堂 | 精品久久洲久久久久护士免费 | 国产小青蛙| 日本公与妇中文在线 | 免费永久观看美女视频网站网址 | 99在线在线视频免费视频观看 | 日韩成a人片在线观看日本 日韩不卡一区二区 | 亚洲+欧美+国产+综合 | 我和子伦系列小说 | 日本男男漫画 |