目的:通過服務端更改多客戶端系統時間,可以通過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('請更改系統時間!')