我正在尝试使用下面的代码从服务器获取横幅。但结果总是说“无”,甚至思想旗帜也存在。我尝试过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?
使用Banner
指令在sshd_config
中配置横幅
# !/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中的一个bug)
通过在^{} 中设置
look_for_keys
和allow_agent
来防止这种情况:下面是一个针对Paramiko的修复程序,它允许在不使用上述解决方法的情况下检索横幅:
https://github.com/paramiko/paramiko/pull/438
相关问题 更多 >
编程相关推荐