更新内容:

1.增加内存信息获取

2.增加电池信息获取

3.增加磁盘信息获取

4.重新布局窗体

5.增加窗体名称

6.增加连接成功之前,不可按压

效果图:

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
>>文件: ps_client.py
>>作者: liu yang
>>邮箱: liuyang0001@outlook.com
>>博客: www.cnblogs.com/liu66blog ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #!/usr/bin/env python
# -*- coding: utf-8 -*- import sys, os
from socket import *
from tkinter import * class Ps_client():
def __init__(self):
self.ip=None
self.port=None
self.data=None
# 创建ipv4套接字
self.client=socket(AF_INET,SOCK_STREAM)
self.root=Tk()
self.root.geometry('300x300+250+250') # 创建IP输入框
var_ip = StringVar()
var_ip.set('localhost')
self.et_ip=Entry(self.root,width=30,textvariable=var_ip)
self.et_ip.pack() # 创建IP输入框的Label
self.ip_lable=Label(self.root,text="ip地址") # 创建端口号输入框
var_port = StringVar()
var_port.set(66)
self.et_port=Entry(self.root,width=30,textvariable=var_port)
# 创建端口号Label
self.port_lable=Label(self.root,text="端口号") # 创建连接按钮,注意!!!command=后面的连接的不加括号
self.connButton=Button(self.root,text="连接",command=self.connect)
# 创建获取cpu按钮
self.getCpuButton=Button(self.root,text="CPU",state='disable',command=self.get_cpu_info)
# 创建获取memory按钮
self.getMemoryButton=Button(self.root,text="内存",state='disable',command=self.get_memory_info)
# 创建获取battery按钮
self.getBatteryButton = Button(self.root, text="电池", state='disable', command=self.get_battery_info)
# 创建获取disk按钮
self.getDiskButton=Button(self.root,text="磁盘",state='disable',command=self.get_disk_info)
# 创建断开按钮
self.exitButton=Button(self.root,text="退出",state='disable',command=self.exit_connect) self.txtBox=Text(self.root,width=40,height=10) def main(self):
self.root.title('博客园:liu66')
self.et_ip.place(x=10,y=20)
self.et_port.place(x=10,y=50)
self.ip_lable.place(x=245,y=20)
self.port_lable.place(x=245,y=50) self.connButton.place(x=10,y=80)
self.getCpuButton.place(x=70,y=80)
self.getMemoryButton.place(x=130,y=80)
self.getBatteryButton.place(x=190,y=80)
self.getDiskButton.place(x=250,y=80)
self.txtBox.place(x=5,y=120)
self.exitButton.place(x=255,y=260)
# self.txtBox.insert(INSERT,'在这里显示内容')
self.root.mainloop() def connect(self):
self.ip=self.et_ip.get()
try:
self.port=int(self.et_port.get())
except ValueError:
self.txtBox.delete(0.0,END)
self.txtBox.insert(0.0,"请输入合法的ip和端口...")
else:
print("ip:%s"%self.ip)
print("port:%s"%self.port)
self.txtBox.delete(0.0,END)
self.txtBox.insert(0.0,"正在链接中...")
try:
self.client.connect((self.ip,self.port))
except OSError:
print("向一个无法连接的网络尝试了一个套接字操作")
self.txtBox.delete(0.0, END)
self.txtBox.insert(0.0, "%s:%d连接失败..."%(self.ip,self.port))
else:
print("%s连接成功..."%self.ip)
self.txtBox.delete(0.0, END)
self.txtBox.insert(0.0, "%s:%d连接成功..."%(self.ip,self.port))
# 连接成功则将其他按钮变为可按状态
self.exitButton['state']='active'
self.getCpuButton['state']='active'
self.getMemoryButton['state']='active'
self.getBatteryButton['state']='active'
self.getDiskButton['state']='active' def get_cpu_info(self):
self.data='cpu'
self.client.send(self.data.encode('utf-8'))
# 将接受的数据装换成浮点数据
cpu_used=float(self.client.recv(1024).decode('utf-8'))
print('CPU使用率:%0.2f'%cpu_used+'%')
self.txtBox.delete(0.0, END)
# 字符串前加上r为防转义
self.txtBox.insert(0.0, "当前的cpu使用率:%0.2f"%cpu_used+r"%") def get_memory_info(self):
self.data='memory'
self.client.send(self.data.encode('utf-8'))
memory_message=self.client.recv(1024).decode('utf-8')
print(memory_message)
# 清除显示
self.txtBox.delete(0.0, END)
# 显示内存信息
self.txtBox.insert(0.0, "%s" %memory_message) def get_battery_info(self):
self.data='battery'
self.client.send(self.data.encode('utf-8'))
battery_message=self.client.recv(1024).decode('utf-8')
print(battery_message)
# 清除显示
self.txtBox.delete(0.0, END)
# 显示内存信息
self.txtBox.insert(0.0, "%s" %battery_message) def get_disk_info(self):
self.data='disk'
self.client.send(self.data.encode('utf-8'))
disk_message=self.client.recv(1024).decode('utf-8')
print(disk_message)
# 清除显示
self.txtBox.delete(0.0, END)
# 显示内存信息
self.txtBox.insert(0.0, "%s" %disk_message) def exit_connect(self):
self.client.close()
self.txtBox.delete(0.0, END)
self.txtBox.insert(0.0, "当前连接已断开...")
print("当前连接已断开...")
self.exitButton['state'] = 'disable'
self.getCpuButton['state'] = 'disable'
self.getMemoryButton['state'] = 'disable'
# 关闭当前窗口
self.root.destroy() if __name__ == '__main__':
Ps=Ps_client()
Ps.main()

[Python Study Notes]CS架构远程访问获取信息--Client端v2.0的更多相关文章

  1. [Python Study Notes]CS架构远程访问获取信息--SERVER端v2.0

    更新内容: 1.增加内存信息获取 2.增加电池信息获取 3.增加磁盘信息获取 4.重新布局窗体 5.增加窗体名称 6.增加连接成功之前,不可按压 ''''''''''''''''''''''''''' ...

  2. [Python Study Notes]CS架构远程访问获取信息--Client端v1.0

    更新内容: 1.添加entry栏默认ip和port口 2.修正退出功能 3.添加退出自动关闭窗口功能 4.优化cpu显示为固定保留两位小数 '''''''''''''''''''''''''''''' ...

  3. [Python Study Notes]CS架构远程访问获取信息--Client端

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  4. [Python Study Notes]CS架构远程访问获取信息--SERVER端

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  5. Eureka系列(三)获取服务Client端具体实现

    获取服务Client 端流程   我们先看下面这张图片,这张图片简单描述了下我们Client是如何获取到Server已续约实例信息的流程:  从图片中我们可以知晓大致流程就是Client会自己开启一个 ...

  6. [Python Study Notes]进程信息(丁丁软件监控进程,http-post)

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  7. [Python Study Notes]cpu信息

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  8. [Python Study Notes]电池信息

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  9. [Python Study Notes]内存信息

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

随机推荐

  1. iOS钉钉远程打卡助手(支持越狱和非越狱)

    前言:本文主要讲述使用hook方式实现钉钉远程打卡功能,涉及到tweak相关知识,如果你不想了解具体实现细节可直接到我的Github地址参考安装(包含越狱和非越狱两种方法)   你是不是像小编一样每个 ...

  2. webpack优化之code splitting

    作为当前风头正盛的打包工具,webpack风靡前端界.确实作为引领了一个时代的打包工具,很多方面都带来了颠覆性的改进,让我们更加的感受到自动化的快感.不过最为大家诟病的一点就是用起来太难了. 要想愉快 ...

  3. 各大型邮箱smtp服务器及端口收集

    >新浪邮箱smtp服务器 外发服务器:smtp.vip.sina.com 收件服务器:pop3.vip.sina.com 新浪免费邮件 外发服务器:smtp.sina.com.cn 收件服务器: ...

  4. ASP.NET Core下发布网站

    一.windows下发布到IIS 1.前奏:IIS上的准备 (1)IIS 必须安装AspNetCoreModule 模块 下载地址:(DotNetCore.2.0.3-WindowsHosting-a ...

  5. IDEA关掉重复代码波浪线

    如图: File----Settings

  6. 阿里云Maven配置,Maven仓库配置,Maven镜像配置

    阿里云Maven配置,Maven仓库配置,Maven镜像配置 ======================== 蕃薯耀 2018年1月29日 http://www.cnblogs.com/fanshu ...

  7. es6重点笔记:let,const

    一,let 先看代码: var a = []; for (var i = 0; i < 10; i++) { a[i] = function () { console.log(i) }; } a ...

  8. Spring Cloud Zuul网关 Filter、熔断、重试、高可用的使用方式。

    时间过的很快,写springcloud(十):服务网关zuul初级篇还在半年前,现在已经是2018年了,我们继续探讨Zuul更高级的使用方式. 上篇文章主要介绍了Zuul网关使用模式,以及自动转发机制 ...

  9. linux_思想

    linux有哪些重要的思想? 1. 做的越多错的越多 2. 纸包不住火 3. 操作重要文件前备份,操作后查看结果 4. 看到命令输出结果,可能命令有个选择直接获得对应值 5. 先定行,再定列

  10. Windows核心编程&错误处理

    知识概要 (1) MAKELANGID Windows宏,用一个来主语言标识和从语言标识创建一个语言标识符 MAKELANGID(ushort usPrimaryLanguage, ushort us ...