2017-10-19 164 views
0
import paramiko 
import re 
import getpass 
username=raw_input("Enter the username: ") 
password=getpass.getpass(prompt="Enter your password: ") 
client = paramiko.client.SSHClient() 
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
client.load_system_host_keys() 
client.connect(host,22,username,password) 
stdin, stdout, stderr= client.exec_command('cat /etc/dhcp/dhcpd.conf') 

我正在尋找獲得dhcpd.conf的輸出保存到一個變量來解析並獲取我需要的信息。我知道我不能打印stdout並獲取我正在查找的信息,但我沒有看到將它發送給變量的另一種方法。你會如何將exec_command的輸出存儲在python中的exec_command

這是在python 2.6.6。任何幫助表示讚賞。

回答

0

標準輸入,標準輸出,標準錯誤的文件句柄 您可以閱讀使用stdout.read() or stdout.readlines() 您可以分配給變量

輸出
相關問題