I am having trouble formatting output from the following code:
import sys
import time
import select
import paramiko
import openpyxl
ip='address'
port='port'
username='uname'
password='pass'
cmd="wstalist | grep -w 'mac\|hostname\|tx\|rx\|lastip\|platform\|distance\|signal'"
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,port,username,password)
stdin,stdout,stderr=ssh.exec_command(cmd)
outlines=stdout.readlines()
resp=''.join(outlines)
print(resp)
Currently the output is exactly as follows:
"mac": "04:18:D6:96:7C:51",
"lastip": "10.1.63.143",
"tx": 130.0,
"rx": 39.0,
"signal": -46,
"distance": 450,
"signal": -44,
"hostname": "Mcdonalds kenako",
"platform": "PowerBeam M5 400",
"signal": -44,
"mac": "80:2A:A8:0E:A3:1E",
"lastip": "10.1.63.190",
"tx": 130.0,
"rx": 130.0,
"signal": -46,
"distance": 450,
"signal": -42,
"hostname": "Lear sewing PE",
"platform": "PowerBeam M5 400",
"signal": -42,
"mac": "80:2A:A8:7C:9A:C2",
"lastip": "10.1.63.189",
"tx": 130.0,
"rx": 117.0,
"signal": -62,
"distance": 4950,
"signal": -60,
"hostname": "Sandoll Consultant",
"platform": "PowerBeam M5 400",
"signal": -58,
"mac": "44:D9:E7:56:E6:CB",
"lastip": "0.0.0.0",
"tx": 130.0,
"rx": 130.0,
"signal": -63,
"distance": 4200,
"signal": -58,
"hostname": "Louise Swart",
"platform": "PowerBeam M5 400",
"signal": -57,
"mac": "04:18:D6:9A:5A:86",
"lastip": "0.0.0.0",
"tx": 130.0,
"rx": 130.0,
"signal": -58,
"distance": 3900,
"signal": -62,
"mac": "44:D9:E7:6A:26:B7",
"lastip": "0.0.0.0",
"tx": 130.0,
"rx": 130.0,
"signal": -64,
"distance": 6750,
"signal": -62,
"hostname": "Larry Hunt",
"platform": "PowerBeam M5 400",
"signal": -62,
"mac": "04:18:D6:98:CA:7F",
"lastip": "0.0.0.0",
"tx": 130.0,
"rx": 130.0,
"signal": -59,
"distance": 6000,
"signal": -60,
"hostname": "Louis Nel",
"platform": "PowerBeam M5 400",
"signal": -59,
"mac": "80:2A:A8:7C:8D:EF",
"lastip": "0.0.0.0",
"tx": 117.0,
"rx": 130.0,
"signal": -63,
"distance": 6900,
"signal": -60,
"hostname": "Florence Naidoo",
"platform": "PowerBeam M5 400",
"signal": -59,
"mac": "80:2A:A8:74:C0:AB",
"lastip": "0.0.0.0",
"tx": 130.0,
"rx": 130.0,
"signal": -47,
"distance": 300,
"signal": -47,
"hostname": "ETC",
"platform": "PowerBeam M5 400",
"signal": -43,
"mac": "80:2A:A8:08:CB:20",
"lastip": "0.0.0.0",
"tx": 130.0,
"rx": 104.0,
"signal": -66,
"distance": 6750,
"signal": -63,
"hostname": "Nicholis Lourens",
"platform": "PowerBeam M5 400",
"signal": -60,
"mac": "00:27:22:56:EC:35",
"lastip": "10.1.63.141",
"tx": 65.0,
"rx": 65.0,
"signal": -62,
"distance": 5400,
"signal": -62,
"hostname": "Africape",
"platform": "AirGrid M5 HP",
"signal": -60,
"mac": "44:D9:E7:2A:43:00",
"lastip": "0.0.0.0",
"tx": 130.0,
"rx": 130.0,
"signal": -59,
"distance": 3000,
"signal": -56,
"hostname": "Ruth Pedzisai",
"platform": "PowerBeam M5 400",
"signal": -55,
"mac": "44:D9:E7:DA:51:28",
"lastip": "0.0.0.0",
"tx": 130.0,
"rx": 130.0,
"signal": -63,
"distance": 3450,
"signal": -60,
"hostname": "Thandeka Tonjeni",
"platform": "PowerBeam M5 400",
"signal": -60,
"mac": "24:A4:3C:90:2F:9F",
"lastip": "0.0.0.0",
"tx": 130.0,
"rx": 130.0,
"signal": -62,
"distance": 5400,
"signal": -61,
"hostname": "WK Construction",
"platform": "PowerBeam M5 400",
"signal": -59,
"mac": "04:18:D6:38:65:01",
"lastip": "0.0.0.0",
"tx": 130.0,
"rx": 130.0,
"signal": -47,
"distance": 2100,
"signal": -48,
"hostname": "OLDBRONCO",
"platform": "PowerBeam M5 400",
"signal": -48,
The indentation you see on the output is as exactly how it is displayed on the out of the command.I thought to mention it in case it would be a factor to the follow:
1) The above is a snippet of a single client's info...I need guidance on removing the second and third instances of the "signal" entry
2) If it will help, I would like the output be represented as follows or (what I really want to actually do) export the information to an Excel spreadsheet:
...Desired Output Format:
Station MAC Device Name IP Address Signal Distance Tx/Rx
00:27:22:54:CB:5E Deon Nelson 192.168.10.1 -66 1950" 144.0/144.0
FYI...This command is run on Ubiquity Wireless devices
I thank you in advance!!!