From 985c3069fb2ccd3488aa600af2daa22186ef162a Mon Sep 17 00:00:00 2001 From: Johan Prins Date: Sat, 15 Oct 2011 13:40:22 +0200 Subject: [PATCH] Adding banner functionality --- paramiko/auth_handler.py | 5 +++++ paramiko/transport.py | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/paramiko/auth_handler.py b/paramiko/auth_handler.py index acb7c8b..da551af 100644 --- a/paramiko/auth_handler.py +++ b/paramiko/auth_handler.py @@ -45,6 +45,7 @@ class AuthHandler (object): self.authenticated = False self.auth_event = None self.auth_method = '' + self.banner = None self.password = None self.private_key = None self.interactive_handler = None @@ -62,6 +63,9 @@ class AuthHandler (object): else: return self.username + def get_banner(self): + return self.banner + def auth_none(self, username, event): self.transport.lock.acquire() try: @@ -375,6 +379,7 @@ class AuthHandler (object): def _parse_userauth_banner(self, m): banner = m.get_string() + self.banner = banner lang = m.get_string() self.transport._log(INFO, 'Auth banner: ' + banner) # who cares. diff --git a/paramiko/transport.py b/paramiko/transport.py index 6c42cc2..951e36a 100644 --- a/paramiko/transport.py +++ b/paramiko/transport.py @@ -1092,6 +1092,18 @@ class Transport (threading.Thread): return None return self.auth_handler.get_username() + def get_banner(self): + """ + Return the banner supplied by the server upon connect. If no banner is supplied, + this method returns C{None}. + + @return: server supplied banner, or C{None}. + @rtype: string + """ + if not self.active or (self.auth_handler is None): + return None + return self.auth_handler.get_banner() + def auth_none(self, username): """ Try to authenticate to the server using no authentication at all.