socket 客户端发送命令
import socket import sys import os,time reload(sys) sys.setdefaultencoding('utf8') def send_cmd(command): try: print "开始连接服务端..." client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.connect(('172.30.10.41', 65000)) #client.settimeout(5) print '开始执行清理命令' client.sendall('clearCache'.encode(utf-8) ) time.sleep(2) client.sendall('close####2232396255592400'.encode(utf-8)) #client.sendall(quote(command + '\n').encode('utf-8')) ##print('======' + ret.encode()) print "执行完成" except Exception as e: print "--------" print e print "---------" finally: client.close() print "已断开连接" if __name__ == '__main__': send_cmd(command)