![](/img/trans.png)
[英]Is there a way using Paramiko and Python to get the banner of the SSH server you connected to?
[英]Fetch prelogin banner from SSH server using Paramiko without authenticating
我正在嘗試使用以下代碼從服務器獲取橫幅。 但結果總是說“無”,甚至認為橫幅存在。 我試過 Python 2 和 3、Paramiko 2.4 和 2.7.0,結果與“無”相同。 任何人都可以糾正/幫助我嗎?
代碼基於: Is there a way using paramiko and python to get the banner of the ssh server you connected to?
橫幅是在sshd_config
中使用Banner
指令配置的。
# !/usr/bin/python
import paramiko
def grab_banner(ip_address, port):
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client.connect(ip_address, port=port, username='username',
password='bad-password-on-purpose')
except:
return client._transport.get_banner()
if __name__ == '__main__':
print grab_banner('192.168.1.26', 22)
謝謝
總的來說,我相信您的代碼應該可以工作。 但是,在密碼驗證失敗后,Paramiko 嘗試了各種其他驗證方法都徒勞無功,進一步的嘗試將丟棄橫幅(在我看來,這就像 Paramiko 中的一個錯誤)。
通過在SSHClient.connect
中設置look_for_keys
和allow_agent
來防止這種情況:
try:
client.connect(ip_address, port=port, username='username',
password='bad-password-on-purpose',
look_for_keys=False, allow_agent=False)
except:
return client._transport.get_banner()
這是 Paramiko 的修復程序,它允許在沒有上述解決方法的情況下檢索橫幅:
https://github.com/paramiko/paramiko/pull/438
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.