服务器端 from socket import * s = socket() s.bind((gethostname(),8888)) s.listen() s, addr = s.accept() print(addr) disk_str = s.recv(1024).decode() disk_list = disk_str.split('\x00') disk_list.pop(-1) print(disk_list) cur_path = " " while True: com_str = input(f'{cur_path}->') com = com_str.split(" ") print(com) if com[0] == 'cd': if len(com) == 1: print(disk_list) cur_path = " " else: if cur_path == " ": cur_path = com[1] else: cur_path = cur_path + '\\' + com[1] com.append(cur_path) elif com[0] == 'dir': if cur_path == " ": print(disk_list) else: temp_str = com_str + " "
客户端
from socket import * from win32api import GetLogicalDriveStrings s = socket() s.connect((gethostname(),8888)) disk_str = GetLogicalDriveStrings() s.send(disk_str.encode())