Repository: ktbyers/netmiko

Issue:
Support for ssh parameter BindAddress
Would it be possible to add support for the 'BindAddress' client option for SSH?  We have management consoles with multiple interfaces and we need to specify which 'source ip address' for the ssh session with the 'BindAddress' statement.  Even though paramiko/netmiko supports user ssh config files, the code does not seem to handle the 'BindAddress' statements.  Ref; https://www.ssh.com/ssh/config/#sec-Listing-of-client-configuration-options

This is already documented on https://github.com/paramiko/paramiko/issues/206


Discussion:
It has to be in Paramiko, if it is not in Paramiko, then I won't be willing to support it.

It looks like from the above that it is not supported in Paramiko?


Kirk
You are absolutely right.  I found that 'paramiko' issue afterward.  But that issue has been opened since 2013!  Doesn't look like it's getting any traction.
I am going to close as it doesn't look like there is a further action for me to do on it.

Resolving patch:
diff --git a/netmiko/base_connection.py b/netmiko/base_connection.py
--- a/netmiko/base_connection.py
+++ b/netmiko/base_connection.py
@@ -75,6 +75,7 @@ def __init__(
         session_log_file_mode="write",
         allow_auto_change=False,
         encoding="ascii",
+        sock=None,
     ):
         """
         Initialize attributes for establishing connection to target device.
@@ -191,6 +192,10 @@ def __init__(
         :param encoding: Encoding to be used when writing bytes to the output channel.
                 (default: ascii)
         :type encoding: str
+
+        :param sock: An open socket or socket-like object (such as a `.Channel`) to use for
+                communication to the target host (default: None).
+        :type sock: socket
         """
         self.remote_conn = None
 
@@ -232,6 +237,7 @@ def __init__(
         self.keepalive = keepalive
         self.allow_auto_change = allow_auto_change
         self.encoding = encoding
+        self.sock = sock
 
         # Netmiko will close the session_log if we open the file
         self.session_log = None
@@ -828,6 +834,7 @@ def _connect_params_dict(self):
             "timeout": self.timeout,
             "auth_timeout": self.auth_timeout,
             "banner_timeout": self.banner_timeout,
+            "sock": self.sock,
         }
 
         # Check if using SSH 'config' file mainly for SSH proxy support


Test patch:
diff --git a/tests/unit/test_base_connection.py b/tests/unit/test_base_connection.py
--- a/tests/unit/test_base_connection.py
+++ b/tests/unit/test_base_connection.py
@@ -59,6 +59,7 @@ def test_use_ssh_file():
         auth_timeout=None,
         banner_timeout=10,
         ssh_config_file=join(RESOURCE_FOLDER, "ssh_config"),
+        sock=None,
     )
 
     connect_dict = connection._connect_params_dict()
@@ -102,6 +103,7 @@ def test_use_ssh_file_proxyjump():
         auth_timeout=None,
         banner_timeout=10,
         ssh_config_file=join(RESOURCE_FOLDER, "ssh_config_proxyjump"),
+        sock=None,
     )
 
     connect_dict = connection._connect_params_dict()
@@ -144,6 +146,7 @@ def test_connect_params_dict():
         auth_timeout=None,
         banner_timeout=10,
         ssh_config_file=None,
+        sock=None,
     )
 
     expected = {
@@ -159,6 +162,7 @@ def test_connect_params_dict():
         "passphrase": None,
         "auth_timeout": None,
         "banner_timeout": 10,
+        "sock": None,
     }
     result = connection._connect_params_dict()
     assert result == expected