Código
from subprocess import STDOUT, PIPE,Popen from tempfile import NamedTemporaryFile command = "iwlist wlan0 scan" tmpout = open("datos.txt","w+") p=Popen(command, stdout=PIPE,stderr=PIPE,shell=True).communicate()[0] aux =p.rfind("Cell ") cantidad = int (p[aux+5:aux+7]) print cantidad lista=[[0 for col in range(9)] for row in range(15)] i=0 aux=0 aux2=0 aux3=0 #numero, ap, canal, calidad, ruido, encriptacion, bitrate while i < cantidad: aux=p.find("Cell ",aux+1) lista[i][0]=i lista[i][1] = p[aux+19:aux+36] aux2=p.find("\"",aux+1) aux3=p.find("\"",aux2+1) lista[i][2] = p[aux2+1:aux3] aux2=p.find("Channel",aux) aux3=p.find("\n",aux2+2) lista[i][3]=p[aux2+8:aux3] aux2=p.find("Quality=",aux) aux2=p.find("=",aux2) aux3=p.find(" ",aux2) lista[i][4]=p[aux2+1:aux3] aux2=p.find("level",aux2) aux2=p.find(":",aux2) aux3=p.find("\n",aux2) lista[i][5]=p[aux2+1:aux3] aux2=p.find("key",aux2) aux2=p.find(":",aux2) aux3=p.find("\n",aux2) lista[i][6]=p[aux2+1:aux3] aux2=p.find("Extra",aux) aux2=p.rfind("Mb/s",aux2) aux3=p.find(" ",aux2-3) lista[i][7]=p[aux2-10:aux3] i=i+1 print p i=0 while i < cantidad: print lista[i][0] print lista[i][1] print lista[i][2] print lista[i][3] print lista[i][4] print lista[i][5] print lista[i][6] print lista[i][7] print "-----------------" i=i+1 print "aca no deberia pasar"
la salida es esta
Código:
bash-3.1# python scan.py
2
wlan0 Scan completed :
Cell 01 - Address: 00:15:6D:65:38:C7
ESSID:"5k Pro1"
Mode:Master
Channel:1
Frequency:2.412 GHz (Channel 1)
Quality=11/100 Signal level:7/100
Encryption key:off
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s
Extra:tsf=0000002b77712736
Extra: Last beacon: 1000ms ago
Cell 02 - Address: 00:24:D2:D6:95:D3
ESSID:"Speedy-WiFi"
Mode:Master
Channel:1
Frequency:2.412 GHz (Channel 1)
Quality=23/100 Signal level:8/100
Encryption key:off
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s
48 Mb/s; 54 Mb/s
Extra:tsf=000000335db5179c
Extra: Last beacon: 968ms ago
0
00:15:6D:65:38:C7
5k Pro1
1
11/100
7/100
off
Mb/s; 54
-----------------
1
00:24:D2:D6:95:D3
Speedy-WiFi
1
23/100
8/100
off
968ms ago
-----------------
aca no deberia pasar
bash-3.1#
Mi pregunta es pork en el ultimo no llega a imprimir como deberia ( Mb/s; 54) y me imprime la final de linea
tmb me gustaria saber como evitar que imprima el final de linea en cada linea, o como concatenar el texto para formar 1 sola linea
Grax!