[Python Study Notes] CS Architecture Remote Access get information--client End v2.0

Source: Internet
Author: User
Tags cpu usage

Update content:

1. Increased Memory information acquisition

2. Increase Battery Information acquisition

3. Increase disk Information acquisition

4. Re-layout the form

5. Add the form name

6. Do not press until the connection is successfully added

:

"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "", "" "". "" "" "" "" "" "" "" "," "" "" "," "" "" "," "" "," "" ">> Ps_client.py>> Author: Liu Yang>> e-mail: [email protected]>> blog: Www.cnblogs.com/liu66blog "" " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "". "" "" "" "" "" "" "" "" "" "" "" "#!/usr/bin/env python#"------        *-Coding:utf-8-*-import sys, osfrom socket import *from tkinter import *class ps_client (): Def __init__ (self): Self.ip=none Self.port=none Self.data=none # Create IPv4 socket Self.client=socket (Af_inet,sock_strea        M) SELF.ROOT=TK () self.root.geometry (' 300x300+250+250 ') # Create IP input Box VAR_IP = Stringvar () Var_ip.set (' localhost ') self.et_ip=entry (SELF.ROOT,WIDTH=30,TEXTVARIABLE=VAR_IP) self.et_ip.pack () # Create the IP input box Label self.ip_lable=label (self.root,text= "IP Address") # Create port number input Box Var_port = Stringvar () var _port.set (self.et_port=entry) (Self.root,widTh=30,textvariable=var_port) # Create port number Label Self.port_lable=label (self.root,text= "Port number") # Create connection button, NOTE!!! Command= the parentheses behind the connection Self.connbutton=button (self.root,text= "Connect", Command=self.connect) # creates the Get CPU button self. Getcpubutton=button (self.root,text= "CPU", state= ' disable ', command=self.get_cpu_info) # Create Get Memory button Self.getm Emorybutton=button (self.root,text= "Memory", state= ' disable ', command=self.get_memory_info) # Create Get Battery button self.ge Tbatterybutton = button (Self.root, text= "Battery", state= ' disable ', command=self.get_battery_info) # Create Get Disk button s Elf.getdiskbutton=button (self.root,text= "Disk", state= ' disable ', command=self.get_disk_info) # Create Disconnect button SELF.EXITB Utton=button (self.root,text= "Exit", state= ' disable ', Command=self.exit_connect) Self.txtbox=text (self.root,width=40 , height=10) def main (self): self.root.title (' Blog Park: 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.ge        Tcpubutton.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, ' Show content here ') Self.root.mainloop () def Connect (self): SELF.IP=SELF.ET_IP.G ET () try:self.port=int (Self.et_port.get ()) except ValueError:self.txtBox.delete (0.0, END) Self.txtBox.insert (0.0, "Please enter a valid IP and port ...") Else:print ("ip:%s"%self.ip) print ("                port:%s "%self.port) self.txtBox.delete (0.0,end) self.txtBox.insert (0.0," in link ... ") Try: Self.client.connect ((self.ip,self.port)) except Oserror:print ("a socket was attempted to a network that cannot be connected Operation ") Self. Txtbox.delete (0.0, END) self.txtBox.insert (0.0, "%s:%d connection failed ..."% (Self.ip,self.port)) Else: Print ("%s connection succeeded ..."%self.ip) self.txtBox.delete (0.0, END) self.txtBox.insert (0.0, "%                s:%d connection succeeded ... "% (Self.ip,self.port)) # The connection is successful and the other button is changed to self.exitbutton[' state ']= ' active ' self.getcpubutton[' state ']= ' active ' self.getmemorybutton[' state ']= ' active ' self.ge tbatterybutton[' state ']= ' active ' self.getdiskbutton[' state ']= ' active ' def get_cpu_info (self): sel F.data= ' CPU ' self.client.send (Self.data.encode (' Utf-8 ')) # Replace the accepted data with floating point data cpu_used=float (SELF.CLIENT.R ECV (1024x768). Decode (' Utf-8 ')) print (' CPU usage:%0.2f '%cpu_used+ '% ') self.txtBox.delete (0.0, END) # string preceded by R Anti-escape Self.txtBox.insert (0.0, "Current CPU Usage:%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 (1024x768). Decode (' Utf-8 ') print (memory_message)  # Clear Show Self.txtBox.delete (0.0, END) # Display memory information 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_mess         AGE=SELF.CLIENT.RECV (1024x768). Decode (' Utf-8 ') print (battery_message) # Clear Show Self.txtBox.delete (0.0, END)         # Display Memory Information 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 (1024x768). Decode (' Utf-8 ') prin T (disk_message) # Clear Show Self.txtBox.delete (0.0, END) # Show memory Information Self.txtBox.insert (0.0, "%s"%dis K_message) def exit_connect (self): Self.client.close () self.txtBox.delete (0.0, END) self.txtBox.in SERT (0.0, "Current connection is disconnected ...")       Print ("Current connection is disconnected ...") self.exitbutton[' state ' = ' disable ' self.getcpubutton[' state '] = ' disable ' self.getmemorybutton[' state ' = ' Disable ' # Close the current window Self.root.destroy () if __name__ = = ' __main__ ': ps=ps_ Client () Ps.main ()

[Python Study notes]cs schema remote access get information--client End v2.0

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.