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

Python Tricks 使用 pywinrm 遠(yuǎn)程控制 Windows 主機(jī)的方法

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

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

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

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

  • 啟用 WinRM 遠(yuǎn)程服務(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"}

方式三:組策略

定位到 計(jì)算機(jī)配置 -> 策略 -> 管理模板 -> Windows 組件 -> Windows 遠(yuǎn)程管理(WinRM) -> WinRM 服務(wù) 。

啟用 允許通過 WinRM 進(jìn)行遠(yuǎn)程服務(wù)器管理允許基本身份驗(yàn)證允許未加密通信 。

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

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

計(jì)算機(jī)配置-> 策略 -> 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 遠(yuǎn)程控制 Windows 主機(jī)的方法的文章就介紹到這了,更多相關(guān)Python Tricks遠(yuǎn)程控制 Windows 主機(jī)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

荃湾区| 法库县| 逊克县| 伊金霍洛旗| 嘉定区| 滨海县| 顺义区| 临湘市| 中阳县| 泰兴市| 富裕县| 溧阳市| 棋牌| 东丽区| 溧阳市| 巨鹿县| 深州市| 廉江市| 来宾市| 寿宁县| 鹤岗市| 句容市| 绩溪县| 班戈县| 贵定县| 景宁| 万盛区| 湾仔区| 西城区| 乐都县| 晋中市| 乃东县| 宁明县| 巢湖市| 微山县| 怀宁县| 泰宁县| 遵义县| 泸水县| 华宁县| 青神县|