Usa re.findall()
:
import re
info= [" sh run vlan 1-4094\r\r\n\r\n!Command: show running-config vlan 1-3967, 4048-4093\r\n!Time: Fri Apr 5 12:57:11 2013\r\n\r\nversion 5.2(1)N1(9b)\r\nvlan 1\r\nvlan 11\r\n name prueba_ado\r\nvlan 15\r\n name VLAN_TRANS\r\nvlan 35\r\n name 353535_old\r\nvlan 42\r\n name VLAN42\r\nvlan 50\r\nvlan 69\r\n name pexise\r\nvlan 89\r\n name andreu\r\nvlan 91\r\n name TEST-OFICINAS\r\nvlan 93\r\n name TEST-SERV_CORP\r\nvlan 94\r\n name Prueba\r\nvlan 95\r\n name TEST-PSP\r\nvlan 96\r\n name Gestio_C296O\r\nvlan 97\r\n name TEST-INTRANET\r\nvlan 99\r\n name TEST-SERV_CORP2\r\nvlan 102\r\n name BAN\r\n private-vlan primary\r\n private-vlan association 1021-1022\r\nvlan 103\r\n name BAN-isolated\r\nvlan 123\r\nvlan 200\r\n name PruebasLucas_ESX1\r\nvlan 201\r\n name PruebasLucas_ESX2\r\nvlan 202\r\n name PruebasLucas_ESX3\r\nvlan 203\r\n name PruebasLucas_ESX4\r\nvlan 304\r\n name PRO_PXE_C1\r\nvlan 446\r\n name TAM_PXE_C1\r\nvlan 471\r\n name INTERNA-SSL\r\nvlan 500\r\n name VLAN_PAL\r\nvlan 556\r\n name toni\r\nvlan 650\r\n name Gest_VMW_ALT\r\nvlan 827\r\n name Proves_VSS_Lab-Ext\r\nvlan 843,845\r\nvlan 848\r\n name AUTODEPLOY\r\nvlan 850\r\nvlan 880\r\n name PXE_PROVISONING_CD1T01\r\nvlan 930\r\n name prueba_backups\r\nvlan 999\r\n name prova2\r\nvlan 1010\r\n name FABRIC_ARISTA\r\nvlan 1021\r\n private-vlan community\r\nvlan 1022\r\n private-vlan isolated\r\nvlan 1031\r\n name ILO_POC_ACI\r\nvlan 1032\r\n name MGMT_POC_ACI\r\nvlan 1033\r\n name POC_ACI\r\nvlan 1190\r\n name SLB-TEST-SLV_INF\r\nvlan 1234\r\n name HOLA\r\nvlan 1250\r\n name PoC_Balanza_RealsOneArm\r\nvlan 1251\r\n name PoC_Balanza_RealsRouted\r\nvlan 1252\r\n name PoC_Balanza_Clients\r\nvlan 1400\r\n name XLAIN_PRO_CD1\r\nvlan 1442\r\nvlan 1475\r\n name Gestion_VMWARE_ADO\r\nvlan 1476\r\n name Vmotion_VMWARE_ADO\r\nvlan 1477\r\n name Servei_VMWARE_ADO\r\nvlan 1478\r\n name ILO_VMWARE_ADO\r\nvlan 1479\r\n name NSX_VTEPS_DC1\r\nvlan 1480\r\n name VMOTION2_DC1\r\nvlan 1481\r\n name NSX_EDGE_DC1\r\nvlan 1482\r\n name EDGE2_NSX_DC1\r\nvlan 1501\r\n name VLAN_ENRUTADA_TEST01\r\nvlan 1502\r\n name VLAN_ENRUTADA_TEST02\r\nvlan 1510\r\n name VLANNN\r\nvlan 1575\r\n name GESTION_DC2\r\nvlan 1576\r\n name Vmotion_VMWARE_ADO_DC2\r\nvlan 1577\r\n name Servei_VMWARE_ADO_DC2\r\nvlan 1579\r\n name NSX_VTEPS_DC2\r\nvlan 1580\r\n name VMOTION2_DC2\r\nvlan 1581\r\n name NSX_EDGE_DC2\r\nvlan 1650\r\n name Gest_VMW_CD1\r\nvlan 1701\r\n name VLAN_INTERCONNECT_TEST01\r\nvlan 1702\r\n name VLAN_INTERCONNECT_TEST02\r\nvlan 1704\r\n name ADA_TESTS_MARZO\r\nvlan 1999\r\n name AutoDeploy_VMware\r\nvlan 2002\r\n name SUBIF\r\nvlan 2479\r\n name VMWARE_NSX_DC2\r\nvlan 2500\r\n name whatever\r\nvlan 2525\r\n name FIREWALLS_LAB\r\nvlan 2527\r\n name Pruebas_PX_Caas\r\nvlan 2650\r\n name Gest_VMW_CD2\r\nvlan 3000-3050\r\nvlan 3901\r\n name FWs_DMZ_TO_PALO\r\nvlan 3902\r\n name FWs_DMZ_TO_JUNIPER\r\nvlan 3903\r\n name FWs_PALO_TO_MZ\r\nvlan 3904\r\n name FWs_JUNIPER_TO_MZ\r\nvlan 3905\r\n name FWs_PALO_TO_JUNIPER\r\nvlan 3906\r\n name FWs_10.31.252.0_BBTEST\r\nvlan 3907\r\n name FWs_PANORAMIX_SYNC\r\nvlan 3908\r\n name FWs_PANORAMA_M500_SYNC\r\nvlan 3909\r\n name FW_CRYPTOAUDITOR_IN\r\nvlan 3910\r\n name FW_CRYPTOAUDITOR_OUT\r\nvlan 3911-3912\r\n\r\n\rCD1SW-BBTBEEG5K-1#"]
hallazgos = re.findall("\r\nvlan (\d*)", info[0])
print(hallazgos )
# ['1', '11', '15', '35', '42', '50', '69', '89', '91', '93', '94', '95', '96', '97', '99', '102', '103', '123', '200', '201', '202', '203', '304', '446', '471', '500', '556', '650', '827', '843', '848', '850', '880', '930', '999', '1010', '1021', '1022', '1031', '1032', '1033', '1190', '1234', '1250', '1251', '1252', '1400', '1442', '1475', '1476', '1477', '1478', '1479', '1480', '1481', '1482', '1501', '1502', '1510', '1575', '1576', '1577', '1579', '1580', '1581', '1650', '1701', '1702', '1704', '1999', '2002', '2479', '2500', '2525', '2527', '2650', '3000', '3901', '3902', '3903', '3904', '3905', '3906', '3907', '3908', '3909', '3910', '3911']
print(",".join(hallazgos))
# 1,11,15,35,42,50,69,89,91,93,94,95,96,97,99,102,103,123,200,201,202,203,304,446,471,500,556,650,827,843,848,850,880,930,999,1010,1021,1022,1031,1032,1033,1190,1234,1250,1251,1252,1400,1442,1475,1476,1477,1478,1479,1480,1481,1482,1501,1502,1510,1575,1576,1577,1579,1580,1581,1650,1701,1702,1704,1999,2002,2479,2500,2525,2527,2650,3000,3901,3902,3903,3904,3905,3906,3907,3908,3909,3910,3911
Pero también buscas obtener los números de los rangos que se encuentran en la cadena de texto.
Para eso primero necesitas recopilar tanto los números simples (los de antes) como los rangos de números, luego, debes iterar por todas los hallazgos en el texto y comprobar a cual de los dos grupos pertenecen, en caso de ser "rangos" crear los rangos apropiados con range()
. Finalmente, iterar por este resultado y aplanar la lista (para que no este anidada en los rangos). Para evitar tener que comprobar si algo es un rango (y por ende iterable) o algo es un número (no iterable) simplemente volvemos los no iterables (números) en tuplas (iterables) -simulando "rangos" de 1 solo item- en la comprensión de lista anterior.
Para eso podemos usar:
hallazgos_en_tuplas = re.findall("\r\nvlan (\d*)-?(\d*)", info[0])
hallazgos_con_rangos = ([int(x[0])] if x[1] == "" else range(int(x[0]), int(x[1])) for x in hallazgos_en_tuplas)
hallazgos_totales = [str(item) for sublist in hallazgos_con_rangos for item in sublist] # El str() solo se necesita si quiere luego usar ",".join() o si quieres que los valores de la lista sean cadenas de texto y no números
print(hallazgos_totales)
# [1, 11, 15, 35, 42, 50, 69, 89, 91, 93, 94, 95, 96, 97, 99, 102, 103, 123, 200, 201, 202, 203, 304, 446, 471, 500, 556, 650, 827, 843, 848, 850, 880, 930, 999, 1010, 1021, 1022, 1031, 1032, 1033, 1190, 1234, 1250, 1251, 1252, 1400, 1442, 1475, 1476, 1477, 1478, 1479, 1480, 1481, 1482, 1501, 1502, 1510, 1575, 1576, 1577, 1579, 1580, 1581, 1650, 1701, 1702, 1704, 1999, 2002, 2479, 2500, 2525, 2527, 2650, 3000, 3001, 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009, 3010, 3011, 3012, 3013, 3014, 3015, 3016, 3017, 3018, 3019, 3020, 3021, 3022, 3023, 3024, 3025, 3026, 3027, 3028, 3029, 3030, 3031, 3032, 3033, 3034, 3035, 3036, 3037, 3038, 3039, 3040, 3041, 3042, 3043, 3044, 3045, 3046, 3047, 3048, 3049, 3901, 3902, 3903, 3904, 3905, 3906, 3907, 3908, 3909, 3910, 3911]
print(",".join(hallazgos_totales))
# 1,11,15,35,42,50,69,89,91,93,94,95,96,97,99,102,103,123,200,201,202,203,304,446,471,500,556,650,827,843,848,850,880,930,999,1010,1021,1022,1031,1032,1033,1190,1234,1250,1251,1252,1400,1442,1475,1476,1477,1478,1479,1480,1481,1482,1501,1502,1510,1575,1576,1577,1579,1580,1581,1650,1701,1702,1704,1999,2002,2479,2500,2525,2527,2650,3000,3001,3002,3003,3004,3005,3006,3007,3008,3009,3010,3011,3012,3013,3014,3015,3016,3017,3018,3019,3020,3021,3022,3023,3024,3025,3026,3027,3028,3029,3030,3031,3032,3033,3034,3035,3036,3037,3038,3039,3040,3041,3042,3043,3044,3045,3046,3047,3048,3049,3901,3902,3903,3904,3905,3906,3907,3908,3909,3910,3911
O si prefiere en una sola línea:
print(",".join(str(item) for sublist in ([int(x[0])] if x[1] == "" else range(int(x[0]), int(x[1])) for x in re.findall("\\r\\nvlan (\d*)-?(\d*)", info[0])) for item in sublist))
# 1,11,15,35,42,50,69,89,91,93,94,95,96,97,99,102,103,123,200,201,202,203,304,446,471,500,556,650,827,843,848,850,880,930,999,1010,1021,1022,1031,1032,1033,1190,1234,1250,1251,1252,1400,1442,1475,1476,1477,1478,1479,1480,1481,1482,1501,1502,1510,1575,1576,1577,1579,1580,1581,1650,1701,1702,1704,1999,2002,2479,2500,2525,2527,2650,3000,3001,3002,3003,3004,3005,3006,3007,3008,3009,3010,3011,3012,3013,3014,3015,3016,3017,3018,3019,3020,3021,3022,3023,3024,3025,3026,3027,3028,3029,3030,3031,3032,3033,3034,3035,3036,3037,3038,3039,3040,3041,3042,3043,3044,3045,3046,3047,3048,3049,3901,3902,3903,3904,3905,3906,3907,3908,3909,3910,3911
Una forma que tal vez sea más sencilla de entender es:
hallazgos_texto = re.findall("\r\nvlan (\d*-\d*|\d*)", info[0])
hallazgos_en_tuplas = (x.split("-") for x in hallazgos_texto)
hallazgos_con_rangos = (range(int(x[0]), int(x[1])) if len(x) == 2 else [x[0]] for x in hallazgos_en_tuplas)
hallazgos_totales = [str(item) for sublist in hallazgos_con_rangos for item in sublist] # Nuevamente, el str() es opcional
print(hallazgos_totales)
# ['1', '11', '15', '35', '42', '50', '69', '89', '91', '93', '94', '95', '96', '97', '99', '102', '103', '123', '200', '201', '202', '203', '304', '446', '471', '500', '556', '650', '827', '843', '848', '850', '880', '930', '999', '1010', '1021', '1022', '1031', '1032', '1033', '1190', '1234', '1250', '1251', '1252', '1400', '1442', '1475', '1476', '1477', '1478', '1479', '1480', '1481', '1482', '1501', '1502', '1510', '1575', '1576', '1577', '1579', '1580', '1581', '1650', '1701', '1702', '1704', '1999', '2002', '2479', '2500', '2525', '2527', '2650', '3000', '3001', '3002', '3003', '3004', '3005', '3006', '3007', '3008', '3009', '3010', '3011', '3012', '3013', '3014', '3015', '3016', '3017', '3018', '3019', '3020', '3021', '3022', '3023', '3024', '3025', '3026', '3027', '3028', '3029', '3030', '3031', '3032', '3033', '3034', '3035', '3036', '3037', '3038', '3039', '3040', '3041', '3042', '3043', '3044', '3045', '3046', '3047', '3048', '3049', '3901', '3902', '3903', '3904', '3905', '3906', '3907', '3908', '3909', '3910', '3911']
print(",".join(hallazgos_totales))
# 1,11,15,35,42,50,69,89,91,93,94,95,96,97,99,102,103,123,200,201,202,203,304,446,471,500,556,650,827,843,848,850,880,930,999,1010,1021,1022,1031,1032,1033,1190,1234,1250,1251,1252,1400,1442,1475,1476,1477,1478,1479,1480,1481,1482,1501,1502,1510,1575,1576,1577,1579,1580,1581,1650,1701,1702,1704,1999,2002,2479,2500,2525,2527,2650,3000,3001,3002,3003,3004,3005,3006,3007,3008,3009,3010,3011,3012,3013,3014,3015,3016,3017,3018,3019,3020,3021,3022,3023,3024,3025,3026,3027,3028,3029,3030,3031,3032,3033,3034,3035,3036,3037,3038,3039,3040,3041,3042,3043,3044,3045,3046,3047,3048,3049,3901,3902,3903,3904,3905,3906,3907,3908,3909,3910,3911
En una sola línea es:
print(",".join(str(item) for sublist in (x.split("-") for x in re.findall("\r\nvlan (\d*-\d*|\d*)", info[0])) for item in sublist))
# 1,11,15,35,42,50,69,89,91,93,94,95,96,97,99,102,103,123,200,201,202,203,304,446,471,500,556,650,827,843,848,850,880,930,999,1010,1021,1022,1031,1032,1033,1190,1234,1250,1251,1252,1400,1442,1475,1476,1477,1478,1479,1480,1481,1482,1501,1502,1510,1575,1576,1577,1579,1580,1581,1650,1701,1702,1704,1999,2002,2479,2500,2525,2527,2650,3000,3050,3901,3902,3903,3904,3905,3906,3907,3908,3909,3910,3911,3912
Si no te gustan las comprensiones de listas avísame y añado un ejemplo sin ellas.