最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2020年07月21日 09:53:44   作者:StarryLand  
這篇文章主要介紹了Python Tricks 使用 pywinrm 遠程控制 Windows 主機的方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

WinRM 即 Windows Remote Management,是微軟對于WS-Management 遠程管理協(xié)議的實現(xiàn)。

一、受控端配置 WinRM 服務(wù)

方式一:cmd 命令行(管理員)

  • 啟用 WinRM 遠程服務(wù): winrm quickconfig
  • 查看 WinRM 服務(wù)監(jiān)聽狀態(tài): 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 認(rèn)證方式: 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 服務(wù) 。

啟用 允許通過 WinRM 進行遠程服務(wù)器管理 、 允許基本身份驗證 、 允許未加密通信

建議同時啟用服務(wù)與防火墻策略:

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

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

二、Python 使用 pywinrm 連接 WinRM 服務(wù)

安裝 pywinrm 庫: pip install pywinrm

執(zhí)行 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'

執(zhí)行 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'

到此這篇關(guān)于Python Tricks 使用 pywinrm 遠程控制 Windows 主機的方法的文章就介紹到這了,更多相關(guān)Python Tricks遠程控制 Windows 主機內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:

相關(guān)文章

最新評論

南京市| 仙居县| 滕州市| 汤阴县| 泾阳县| 凌源市| 盐城市| 遵义市| 赣榆县| 肇东市| 新营市| 宜城市| 景德镇市| 临猗县| 天气| 新乐市| 红安县| 郑州市| 德令哈市| 东丽区| 平定县| 郧西县| 迁西县| 义马市| 翁牛特旗| 张家川| 尚志市| 大渡口区| 平阴县| 屏东县| 大余县| 云南省| 奇台县| 惠来县| 佛教| 新绛县| 太仓市| 新郑市| 巴林左旗| 尉氏县| 宕昌县|