Server-side script:
1 #!/usr/bin/env python2 #Coding:utf83 fromSocketImport*4 ImportOS5 Import time6host="'7port=215678bufsiz=10249Addr=(host,port)Ten oneTcpsersock =Socket (af_inet,sock_stream) aTcpsersock.bind (ADDR)#Creating Sockets -Tcpsersock.listen (5)#Number of connections -Dic={} the whileTrue: -tcpclisock, addr = tcpsersock.accept ()#Accept client Connections -data = Tcpclisock.recv (bufsiz)#receiving client Data -Tcpclisock.close ()#shutting down the client +dic[addr[0]]=Data.split () -Os.system ('Touch System_info') +string="' a forKinchdic: ats = k +' '+ dic[k][0] +' '+ dic[k][1] +' '+dic[k][2] -string+=','. Join (s.split ()) +'\ n' #Convert a string to a comma by a hollow lattice -With open ('System_info','W') as F: -F.write (string)
Client Script:
1 #!/usr/bin/env python2 #Coding:utf83 fromSocketImport*4 ImportOS5 fromTimeImportSleep6host='192.168.1.226'7port=215678bufsiz=10249Addr=(host,port)Ten one whileTrue: aTcpclisock =Socket (af_inet, Sock_stream) -Tcpclisock.connect (ADDR)#try to connect - whileTrue: thedata = Os.popen ("free-h | head-2 | tail-1 | awk ' {print $2,$3} '"). Read (). strip ('\ n') + - ' '+ Os.popen ("Vmstat | tail-1 | awk-f "' {print $} '"). Read (). strip ('\ n') - PrintData -Tcpclisock.send (data)#Send Message + break -Tcpclisock.close ()#Close Client Connections +Sleep (5)
The server end of the implementation of the Client's ip, total memory, using memory, the CPU is written into the text in a string.
Cases:
192.168.1.121,15g,3.1g,100
192.168.1.42,125g,7.3g,100
192.168.1.43,125g,2.2g,100
Python TCP Socket Transport server Resource information (c/s)