Python实现的远程登录windows系统功能示例
作者:hello_lxc 时间:2022-10-09 21:26:15
本文实例讲述了Python实现的远程登录windows系统功能。分享给大家供大家参考,具体如下:
首先安装wmi
命令:
pip install wmi
然后会报错缺少pywin32-219.win-amd64-py2.7.exe包,去下面这个地址下载
http://sourceforge.net/projects/pywin32/files/pywin32/
寻找适合自己电脑位数和python的包下载安装
下面是远程连接的代码:
# -*- coding:utf-8 -*-
#! python2
import wmi
def sys_version(ipaddress, user, password):
conn = wmi.WMI(computer=ipaddress, user=user, password=password)
for sys in conn.Win32_OperatingSystem():
print "Version:%s" % sys.Caption.encode("UTF8"),"Vernum:%s" % sys.BuildNumber #系统信息
print sys.OSArchitecture.encode("UTF8") # 系统的位数
print sys.NumberOfProcesses # 系统的进程数
if __name__ == '__main__':
sys_version(ipaddress="ip", user="用户名", password="密码")
附:python使用socket远程执行命令,并返回值操作示例
#!/usr/bin/env python
# TCP-Server
import socket
import subprocess
sk_obj = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sk_obj.bind(('127.0.0.1',8000))
sk_obj.listen(5)
while True:
conn,ipaddr = sk_obj.accept()
print ('connection from ip: %s' % ipaddr[0])
while True:
try:
from_recv = conn.recv(8096)
if len(from_recv) == 0:continue
print ('from ip : %s information : %s' % (ipaddr[0],from_recv))
res = subprocess.Popen(from_recv.decode('utf-8'),shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
msg = res.stdout.read()
if len(msg) == 0:
msg = res.stderr.read()
conn.send(msg)
except Exception:
break
conn.close()
sk_obj.close()
#!/usr/bin/env python
# TCP-Client
import socket
import sys
sk_obj=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sk_obj.connect(('127.0.0.1',8000))
while True:
msg = raw_input('-->').strip()
if len(msg)==0:continue
sk_obj.send(msg.encode('utf-8'))
data = sk_obj.recv(8096)
print ('Server send information : %s' % data.decode('utf-8'))
sk_obj.close()
希望本文所述对大家Python程序设计有所帮助。
来源:https://blog.csdn.net/hello_lxc/article/details/49488731
标签:Python,远程登录,windows系统


猜你喜欢
VS2013连接MySQL5.6成功案例一枚
2024-01-20 17:36:51

一小时学会TensorFlow2之全连接层
2022-11-27 10:35:30

Python新手学习标准库模块命名
2021-01-16 05:18:06
Python3使用PySynth制作音乐的方法
2021-03-18 19:41:01

GO语言求100以内的素数
2024-05-08 10:13:41
Python处理中文标点符号大集合
2021-12-07 16:03:45
详解python的数字类型变量与其方法
2023-12-05 18:40:53
Python对两个有序列表进行合并和排序的例子
2022-06-07 00:11:37
从0编写区块链之用python解释区块链最基本原理
2022-07-20 10:08:24
Python编程入门的一些基本知识
2023-09-07 00:07:24

Python列表推导式与生成器用法分析
2022-03-21 12:06:54
如何让python的运行速度得到提升
2023-04-26 21:48:35
Flask框架通过Flask_login实现用户登录功能示例
2021-07-19 07:15:38

最新PyCharm从安装到PyCharm永久激活再到PyCharm官方中文汉化详细教程
2022-09-24 01:38:47

Python3 多线程(连接池)操作MySQL插入数据
2024-01-27 14:32:57

JavaScript入门教程(7) History历史对象
2024-05-11 10:23:47
Pytorch-LSTM输入输出参数方式
2021-02-22 18:49:28

sql查询一个数组中是否包含某个内容find_in_set问题
2024-01-23 19:55:12
vue-cli 2.*中导入公共less文件的方法步骤
2024-04-28 10:54:01
WxPython建立批量录入框窗口
2023-11-18 15:47:00