# list interfaces status, find ADM ports ser.read_all() ser.write('dis int brief\n'.encode('utf8')) time.sleep(1) data = str(ser.read_all(), encoding='utf8') print(data) data = data.split('\n')
ports = [] for item in data: if item.find(r'ADM') != -1: port = item.split(r' ')[0] if port.find(r'GE') != -1: ports.append(port)
for port in ports: ser.read_all() ser.write(('int ' + port + '\nundo shutdown\n').encode('utf8')) ser.write('quit\n'.encode('utf8')) time.sleep(1) print(str(ser.read_all(), encoding='utf8'))
ser.write('vlan 2002\n'.encode('utf8')) time.sleep(1) print(str(ser.read_all(), encoding='utf8')) for port in ports: ser.read_all() ser.write(('port GE1/0/' + port + '\n').encode('utf8')) ser.write('quit\n'.encode('utf8')) time.sleep(1) print(str(ser.read_all(), encoding='utf8'))