I am having trouble receiving the complete output of a command run from a Python script with paramiko using SSH to connect to the router.
When I run ‘ip firewall connection print’ in the terminal on the router GUI it prints the whole connections table along with all the columns with data rates and whatnot.
When I run the same command from the python script, it manages to connect and print the output but only part of it. The last column is TCP-STATE and the rest does not get printed out.
I think I know what the catch is. When I run the command from a Putty terminal while it is not fullscreen it does the same thing - prints only part of the table. When I fullscreen it, it prints out the whole table. So I presume the terminal window (which is of course invisible to me) that the script opens is not big enough to hold all of the columns so only part of it gets printed out.
Here is the script :
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('myDefaultGateway', username='myUsername', password='myPassword')
stdin, stdout, stderr = client.exec_command('ip firewall connection print')
for line in stdout:
print(line.strip('\n'))
client.close()
I run the script via cmd and redirect the output to a file. What can I do to make the script show all the data? I am looking for the data rates for each of the IPs but that part is missing.
C:\Users\nbctc\AppData\Local\Programs\Python\Python310\python.exe D:/TES/cisco2/coba2.py
Flags: E - expected; S - seen-reply; A - assured; C - confirmed; D - dying;
F - fasttrack; H - hw-offload; s - srcnat; d - dstnat
# PR.. SRC-ADDRESS DST-ADDRESS TCP-STATE
0 SAC F s tcp 192.168.88.137:33536 23.52.40.177:443 established
1 SAC F s tcp 192.168.88.134:40378 199.232.46.73:443 established
2 SAC F s tcp 192.168.88.137:39548 119.28.123.116:1883 established