发布时间:2019-08-05 16:35:13编辑:auto阅读(1304)
目的:通过服务端更改多客户端系统时间,可以通过socket有很多扩展应用
下面是script部分
一,服务端
#!/usr/bin/python # -*- coding:utf-8 -*- #Version:1.0.0 #Author:liyinda from socket import * import os,sys CliHost = sys.argv[1] CliPort = 5555 Input = raw_input("input:") Message = str(Input) try: Sock = socket(AF_INET,SOCK_STREAM) Sock.connect((CliHost,CliPort)) Sock.send(Message) Data = Sock.recv(1024) print '==>',Data Sock.close() except Exception: print '无法更改系统时间!'
二,客户端
#!/usr/bin/python # -*- coding:utf-8 -*- #Version:1.0.0 #Author:liyinda from socket import * import os MyHost = '' MyPort = 5555 SockObj = socket(AF_INET,SOCK_STREAM) SockObj.bind((MyHost,MyPort)) SockObj.listen(True) while True: connection,address = SockObj.accept() print '===>',address[0] CMD = connection.recv(1024) print CMD if str(CMD).find('date',0,4) == 0: os.system(str(CMD)) SendCMD = os.popen(str(CMD)).read() connection.sendall(str(SendCMD)) connection.close() else: connection.sendall('请更改系统时间!')
上一篇: 我的python学习--第四天
下一篇: 再述:python中redis的使用(P
47494
45794
36792
34323
28960
25598
24443
19611
19111
17632
5466°
6048°
5570°
5638°
6573°
5376°
5378°
5884°
5855°
7170°