Package paramiko :: Module transport :: Class Transport
[frames] | no frames]

Class Transport

source code

        object --+        
                 |        
threading._Verbose --+    
                     |    
      threading.Thread --+
                         |
                        Transport

An SSH Transport attaches to a stream (usually a socket), negotiates an encrypted session, authenticates, and then creates stream tunnels, called `channels <.Channel>`, across the session. Multiple channels can be multiplexed across a single session (and often are, in the case of port forwardings).

Instance Methods
 
__init__(self, sock)
Create a new SSH session over an existing socket, or socket-like object.
source code
 
__repr__(self)
Returns a string representation of this object, for debugging.
source code
 
atfork(self)
Terminate this Transport without closing the session.
source code
 
get_security_options(self)
Return a `.SecurityOptions` object which can be used to tweak the encryption algorithms this transport will permit (for encryption, digest/hash operations, public keys, and key exchanges) and the order of preference for them.
source code
 
start_client(self, event=None)
Negotiate a new SSH2 session as a client.
source code
 
start_server(self, event=None, server=None)
Negotiate a new SSH2 session as a server.
source code
 
add_server_key(self, key)
Add a host key to the list of keys used for server mode.
source code
 
get_server_key(self)
Return the active host key, in server mode.
source code
 
close(self)
Close this session, and any open channels that are tied to it.
source code
 
get_remote_server_key(self)
Return the host key of the server (in client mode).
source code
 
is_active(self)
Return true if this session is active (open).
source code
 
open_session(self)
Request a new channel to the server, of type ``"session"``.
source code
 
open_x11_channel(self, src_addr=None)
Request a new channel to the client, of type ``"x11"``.
source code
 
open_forward_agent_channel(self)
Request a new channel to the client, of type ``"auth-agent@openssh.com"``.
source code
 
open_forwarded_tcpip_channel(self, src_addr, dest_addr)
Request a new channel back to the client, of type ``"forwarded-tcpip"``.
source code
 
open_channel(self, kind, dest_addr=None, src_addr=None)
Request a new channel to the server.
source code
 
request_port_forward(self, address, port, handler=None)
Ask the server to forward TCP connections from a listening port on the server, across this SSH session.
source code
 
cancel_port_forward(self, address, port)
Ask the server to cancel a previous port-forwarding request.
source code
 
open_sftp_client(self)
Create an SFTP client channel from an open transport.
source code
 
send_ignore(self, byte_count=None)
Send a junk packet across the encrypted link.
source code
 
renegotiate_keys(self)
Force this session to switch to new keys.
source code
 
set_keepalive(self, interval)
Turn on/off keepalive packets (default is off).
source code
 
global_request(self, kind, data=None, wait=True)
Make a global request to the remote host.
source code
 
accept(self, timeout=None)
Return the next channel opened by the client over this transport, in server mode.
source code
 
connect(self, hostkey=None, username='', password=None, pkey=None)
Negotiate an SSH2 session, and optionally verify the server's host key and authenticate using a password or private key.
source code
 
get_exception(self)
Return any exception that happened during the last server request.
source code
 
set_subsystem_handler(self, name, handler, *larg, **kwarg)
Set the handler class for a subsystem in server mode.
source code
 
is_authenticated(self)
Return true if this session is active and authenticated.
source code
 
get_username(self)
Return the username this connection is authenticated for.
source code
string
get_banner(self)
Return the banner supplied by the server upon connect.
source code
 
auth_none(self, username)
Try to authenticate to the server using no authentication at all.
source code
 
auth_password(self, username, password, event=None, fallback=True)
Authenticate to the server using a password.
source code
 
auth_publickey(self, username, key, event=None)
Authenticate to the server using a private key.
source code
 
auth_interactive(self, username, handler, submethods='')
Authenticate to the server interactively.
source code
 
set_log_channel(self, name)
Set the channel for this transport's logging.
source code
 
get_log_channel(self)
Return the channel name used for this transport's logging.
source code
 
set_hexdump(self, hexdump)
Turn on/off logging a hex dump of protocol traffic at DEBUG level in the logs.
source code
 
get_hexdump(self)
Return ``True`` if the transport is currently logging hex dumps of protocol traffic.
source code
 
use_compression(self, compress=True)
Turn on/off compression.
source code
 
getpeername(self)
Return the address of the remote side of this Transport, if possible.
source code
 
stop_thread(self) source code
 
run(self) source code

Inherited from threading.Thread: getName, isAlive, isDaemon, is_alive, join, setDaemon, setName, start

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods
 
load_server_moduli(filename=None)
(optional) Load a file of prime moduli for use in doing group-exchange key negotiation in server mode.
source code
Properties

Inherited from threading.Thread: daemon, ident, name

Inherited from object: __class__

Method Details

__init__(self, sock)
(Constructor)

source code 

Create a new SSH session over an existing socket, or socket-like
object.  This only creates the `.Transport` object; it doesn't begin the
SSH session yet.  Use `connect` or `start_client` to begin a client
session, or `start_server` to begin a server session.

If the object is not actually a socket, it must have the following
methods:

- ``send(str)``: Writes from 1 to ``len(str)`` bytes, and returns an
  int representing the number of bytes written.  Returns
  0 or raises ``EOFError`` if the stream has been closed.
- ``recv(int)``: Reads from 1 to ``int`` bytes and returns them as a
  string.  Returns 0 or raises ``EOFError`` if the stream has been
  closed.
- ``close()``: Closes the socket.
- ``settimeout(n)``: Sets a (float) timeout on I/O operations.

For ease of use, you may also pass in an address (as a tuple) or a host
string as the ``sock`` argument.  (A host string is a hostname with an
optional port (separated by ``":"``) which will be converted into a
tuple of ``(hostname, port)``.)  A socket will be connected to this
address and used for communication.  Exceptions from the ``socket``
call may be thrown in this case.

:param socket sock:
    a socket or socket-like object to create the session over.

Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 

Returns a string representation of this object, for debugging.

Overrides: object.__repr__

atfork(self)

source code 

Terminate this Transport without closing the session. On posix systems, if a Transport is open during process forking, both parent and child will share the underlying socket, but only one process can use the connection (without corrupting the session). Use this method to clean up a Transport object without disrupting the other process.

.. versionadded:: 1.5.3

start_client(self, event=None)

source code 

Negotiate a new SSH2 session as a client.  This is the first step after
creating a new `.Transport`.  A separate thread is created for protocol
negotiation.

If an event is passed in, this method returns immediately.  When
negotiation is done (successful or not), the given ``Event`` will
be triggered.  On failure, `is_active` will return ``False``.

(Since 1.4) If ``event`` is ``None``, this method will not return until
negotation is done.  On success, the method returns normally.
Otherwise an SSHException is raised.

After a successful negotiation, you will usually want to authenticate,
calling `auth_password <Transport.auth_password>` or
`auth_publickey <Transport.auth_publickey>`.

.. note:: `connect` is a simpler method for connecting as a client.

.. note:: After calling this method (or `start_server` or `connect`),
    you should no longer directly read from or write to the original
    socket object.

:param .threading.Event event:
    an event to trigger when negotiation is complete (optional)

:raises SSHException: if negotiation fails (and no ``event`` was passed
    in)

start_server(self, event=None, server=None)

source code 

Negotiate a new SSH2 session as a server.  This is the first step after
creating a new `.Transport` and setting up your server host key(s).  A
separate thread is created for protocol negotiation.

If an event is passed in, this method returns immediately.  When
negotiation is done (successful or not), the given ``Event`` will
be triggered.  On failure, `is_active` will return ``False``.

(Since 1.4) If ``event`` is ``None``, this method will not return until
negotation is done.  On success, the method returns normally.
Otherwise an SSHException is raised.

After a successful negotiation, the client will need to authenticate.
Override the methods `get_allowed_auths
<.ServerInterface.get_allowed_auths>`, `check_auth_none
<.ServerInterface.check_auth_none>`, `check_auth_password
<.ServerInterface.check_auth_password>`, and `check_auth_publickey
<.ServerInterface.check_auth_publickey>` in the given ``server`` object
to control the authentication process.

After a successful authentication, the client should request to open a
channel.  Override `check_channel_request
<.ServerInterface.check_channel_request>` in the given ``server``
object to allow channels to be opened.

.. note::
    After calling this method (or `start_client` or `connect`), you
    should no longer directly read from or write to the original socket
    object.

:param .threading.Event event:
    an event to trigger when negotiation is complete.
:param .ServerInterface server:
    an object used to perform authentication and create `channels
    <.Channel>`

:raises SSHException: if negotiation fails (and no ``event`` was passed
    in)

add_server_key(self, key)

source code 

Add a host key to the list of keys used for server mode.  When behaving
as a server, the host key is used to sign certain packets during the
SSH2 negotiation, so that the client can trust that we are who we say
we are.  Because this is used for signing, the key must contain private
key info, not just the public half.  Only one key of each type (RSA or
DSS) is kept.

:param .PKey key:
    the host key to add, usually an `.RSAKey` or `.DSSKey`.

get_server_key(self)

source code 

Return the active host key, in server mode.  After negotiating with the
client, this method will return the negotiated host key.  If only one
type of host key was set with `add_server_key`, that's the only key
that will ever be returned.  But in cases where you have set more than
one type of host key (for example, an RSA key and a DSS key), the key
type will be negotiated by the client, and this method will return the
key of the type agreed on.  If the host key has not been negotiated
yet, ``None`` is returned.  In client mode, the behavior is undefined.

:return:
    host key (`.PKey`) of the type negotiated by the client, or
    ``None``.

load_server_moduli(filename=None)
Static Method

source code 

(optional)
Load a file of prime moduli for use in doing group-exchange key
negotiation in server mode.  It's a rather obscure option and can be
safely ignored.

In server mode, the remote client may request "group-exchange" key
negotiation, which asks the server to send a random prime number that
fits certain criteria.  These primes are pretty difficult to compute,
so they can't be generated on demand.  But many systems contain a file
of suitable primes (usually named something like ``/etc/ssh/moduli``).
If you call `load_server_moduli` and it returns ``True``, then this
file of primes has been loaded and we will support "group-exchange" in
server mode.  Otherwise server mode will just claim that it doesn't
support that method of key negotiation.

:param str filename:
    optional path to the moduli file, if you happen to know that it's
    not in a standard location.
:return:
    True if a moduli file was successfully loaded; False otherwise.

.. note:: This has no effect when used in client mode.

get_remote_server_key(self)

source code 

Return the host key of the server (in client mode).

.. note:

   Previously this call returned a tuple of ``(key type, key
   string)``. You can get the same effect by calling `.PKey.get_name`
   for the key type, and ``str(key)`` for the key string.

:raises SSHException: if no session is currently active.

:return: public key (`.PKey`) of the remote server

is_active(self)

source code 

Return true if this session is active (open).

:return:
    True if the session is still active (open); False if the session is
    closed

open_session(self)

source code 

Request a new channel to the server, of type ``"session"``.  This is
just an alias for calling `open_channel` with an argument of
``"session"``.

:return: a new `.Channel`

:raises SSHException: if the request is rejected or the session ends
    prematurely

open_x11_channel(self, src_addr=None)

source code 

Request a new channel to the client, of type ``"x11"``.  This
is just an alias for ``open_channel('x11', src_addr=src_addr)``.

:param tuple src_addr:
    the source address (``(str, int)``) of the x11 server (port is the
    x11 port, ie. 6010)
:return: a new `.Channel`

:raises SSHException: if the request is rejected or the session ends
    prematurely

open_forward_agent_channel(self)

source code 

Request a new channel to the client, of type
``"auth-agent@openssh.com"``.

This is just an alias for ``open_channel('auth-agent@openssh.com')``.

:return: a new `.Channel`

:raises SSHException:
    if the request is rejected or the session ends prematurely

open_forwarded_tcpip_channel(self, src_addr, dest_addr)

source code 

Request a new channel back to the client, of type ``"forwarded-tcpip"``. This is used after a client has requested port forwarding, for sending incoming connections back to the client.

:param src_addr: originator's address :param dest_addr: local (server) connected address

open_channel(self, kind, dest_addr=None, src_addr=None)

source code 

Request a new channel to the server. `Channels <.Channel>` are
socket-like objects used for the actual transfer of data across the
session. You may only request a channel after negotiating encryption
(using `connect` or `start_client`) and authenticating.

:param str kind:
    the kind of channel requested (usually ``"session"``,
    ``"forwarded-tcpip"``, ``"direct-tcpip"``, or ``"x11"``)
:param tuple dest_addr:
    the destination address (address + port tuple) of this port
    forwarding, if ``kind`` is ``"forwarded-tcpip"`` or
    ``"direct-tcpip"`` (ignored for other channel types)
:param src_addr: the source address of this port forwarding, if
    ``kind`` is ``"forwarded-tcpip"``, ``"direct-tcpip"``, or ``"x11"``
:return: a new `.Channel` on success

:raises SSHException: if the request is rejected or the session ends
    prematurely

request_port_forward(self, address, port, handler=None)

source code 

Ask the server to forward TCP connections from a listening port on
the server, across this SSH session.

If a handler is given, that handler is called from a different thread
whenever a forwarded connection arrives.  The handler parameters are::

    handler(channel, (origin_addr, origin_port), (server_addr, server_port))

where ``server_addr`` and ``server_port`` are the address and port that
the server was listening on.

If no handler is set, the default behavior is to send new incoming
forwarded connections into the accept queue, to be picked up via
`accept`.

:param str address: the address to bind when forwarding
:param int port:
    the port to forward, or 0 to ask the server to allocate any port
:param callable handler:
    optional handler for incoming forwarded connections, of the form
    ``func(Channel, (str, int), (str, int))``.
:return: the port number (`int`) allocated by the server

:raises SSHException: if the server refused the TCP forward request

cancel_port_forward(self, address, port)

source code 

Ask the server to cancel a previous port-forwarding request. No more connections to the given address & port will be forwarded across this ssh connection.

:param str address: the address to stop forwarding :param int port: the port to stop forwarding

open_sftp_client(self)

source code 

Create an SFTP client channel from an open transport.  On success, an
SFTP session will be opened with the remote host, and a new
`.SFTPClient` object will be returned.

:return:
    a new `.SFTPClient` referring to an sftp session (channel) across
    this transport

send_ignore(self, byte_count=None)

source code 

Send a junk packet across the encrypted link.  This is sometimes used
to add "noise" to a connection to confuse would-be attackers.  It can
also be used as a keep-alive for long lived connections traversing
firewalls.

:param int byte_count:
    the number of random bytes to send in the payload of the ignored
    packet -- defaults to a random number from 10 to 41.

renegotiate_keys(self)

source code 

Force this session to switch to new keys.  Normally this is done
automatically after the session hits a certain number of packets or
bytes sent or received, but this method gives you the option of forcing
new keys whenever you want.  Negotiating new keys causes a pause in
traffic both ways as the two sides swap keys and do computations.  This
method returns when the session has switched to new keys.

:raises SSHException: if the key renegotiation failed (which causes the
    session to end)

set_keepalive(self, interval)

source code 

Turn on/off keepalive packets (default is off).  If this is set, after
``interval`` seconds without sending any data over the connection, a
"keepalive" packet will be sent (and ignored by the remote host).  This
can be useful to keep connections alive over a NAT, for example.

:param int interval:
    seconds to wait before sending a keepalive packet (or
    0 to disable keepalives).

global_request(self, kind, data=None, wait=True)

source code 

Make a global request to the remote host.  These are normally
extensions to the SSH2 protocol.

:param str kind: name of the request.
:param tuple data:
    an optional tuple containing additional data to attach to the
    request.
:param bool wait:
    ``True`` if this method should not return until a response is
    received; ``False`` otherwise.
:return:
    a `.Message` containing possible additional data if the request was
    successful (or an empty `.Message` if ``wait`` was ``False``);
    ``None`` if the request was denied.

accept(self, timeout=None)

source code 

Return the next channel opened by the client over this transport, in
server mode.  If no channel is opened before the given timeout, ``None``
is returned.

:param int timeout:
    seconds to wait for a channel, or ``None`` to wait forever
:return: a new `.Channel` opened by the client

connect(self, hostkey=None, username='', password=None, pkey=None)

source code 

Negotiate an SSH2 session, and optionally verify the server's host key
and authenticate using a password or private key.  This is a shortcut
for `start_client`, `get_remote_server_key`, and
`Transport.auth_password` or `Transport.auth_publickey`.  Use those
methods if you want more control.

You can use this method immediately after creating a Transport to
negotiate encryption with a server.  If it fails, an exception will be
thrown.  On success, the method will return cleanly, and an encrypted
session exists.  You may immediately call `open_channel` or
`open_session` to get a `.Channel` object, which is used for data
transfer.

.. note::
    If you fail to supply a password or private key, this method may
    succeed, but a subsequent `open_channel` or `open_session` call may
    fail because you haven't authenticated yet.

:param .PKey hostkey:
    the host key expected from the server, or ``None`` if you don't
    want to do host key verification.
:param str username: the username to authenticate as.
:param str password:
    a password to use for authentication, if you want to use password
    authentication; otherwise ``None``.
:param .PKey pkey:
    a private key to use for authentication, if you want to use private
    key authentication; otherwise ``None``.

:raises SSHException: if the SSH2 negotiation fails, the host key
    supplied by the server is incorrect, or authentication fails.

get_exception(self)

source code 

Return any exception that happened during the last server request.
This can be used to fetch more specific error information after using
calls like `start_client`.  The exception (if any) is cleared after
this call.

:return:
    an exception, or ``None`` if there is no stored exception.

.. versionadded:: 1.1

set_subsystem_handler(self, name, handler, *larg, **kwarg)

source code 

Set the handler class for a subsystem in server mode.  If a request
for this subsystem is made on an open ssh channel later, this handler
will be constructed and called -- see `.SubsystemHandler` for more
detailed documentation.

Any extra parameters (including keyword arguments) are saved and
passed to the `.SubsystemHandler` constructor later.

:param str name: name of the subsystem.
:param class handler:
    subclass of `.SubsystemHandler` that handles this subsystem.

is_authenticated(self)

source code 

Return true if this session is active and authenticated.

:return:
    True if the session is still open and has been authenticated
    successfully; False if authentication failed and/or the session is
    closed.

get_username(self)

source code 

Return the username this connection is authenticated for. If the session is not authenticated (or authentication failed), this method returns ``None``.

:return: username that was authenticated (a `str`), or ``None``.

get_banner(self)

source code 

Return the banner supplied by the server upon connect. If no banner is supplied, this method returns None.

Returns: string
server supplied banner, or None.

auth_none(self, username)

source code 

Try to authenticate to the server using no authentication at all.
This will almost always fail.  It may be useful for determining the
list of authentication types supported by the server, by catching the
`.BadAuthenticationType` exception raised.

:param str username: the username to authenticate as
:return:
    `list` of auth types permissible for the next stage of
    authentication (normally empty)

:raises BadAuthenticationType: if "none" authentication isn't allowed
    by the server for this user
:raises SSHException: if the authentication failed due to a network
    error

.. versionadded:: 1.5

auth_password(self, username, password, event=None, fallback=True)

source code 

Authenticate to the server using a password.  The username and password
are sent over an encrypted link.

If an ``event`` is passed in, this method will return immediately, and
the event will be triggered once authentication succeeds or fails.  On
success, `is_authenticated` will return ``True``.  On failure, you may
use `get_exception` to get more detailed error information.

Since 1.1, if no event is passed, this method will block until the
authentication succeeds or fails.  On failure, an exception is raised.
Otherwise, the method simply returns.

Since 1.5, if no event is passed and ``fallback`` is ``True`` (the
default), if the server doesn't support plain password authentication
but does support so-called "keyboard-interactive" mode, an attempt
will be made to authenticate using this interactive mode.  If it fails,
the normal exception will be thrown as if the attempt had never been
made.  This is useful for some recent Gentoo and Debian distributions,
which turn off plain password authentication in a misguided belief
that interactive authentication is "more secure".  (It's not.)

If the server requires multi-step authentication (which is very rare),
this method will return a list of auth types permissible for the next
step.  Otherwise, in the normal case, an empty list is returned.

:param str username: the username to authenticate as
:param basestring password: the password to authenticate with
:param .threading.Event event:
    an event to trigger when the authentication attempt is complete
    (whether it was successful or not)
:param bool fallback:
    ``True`` if an attempt at an automated "interactive" password auth
    should be made if the server doesn't support normal password auth
:return:
    `list` of auth types permissible for the next stage of
    authentication (normally empty)

:raises BadAuthenticationType: if password authentication isn't
    allowed by the server for this user (and no event was passed in)
:raises AuthenticationException: if the authentication failed (and no
    event was passed in)
:raises SSHException: if there was a network error

auth_publickey(self, username, key, event=None)

source code 

Authenticate to the server using a private key.  The key is used to
sign data from the server, so it must include the private part.

If an ``event`` is passed in, this method will return immediately, and
the event will be triggered once authentication succeeds or fails.  On
success, `is_authenticated` will return ``True``.  On failure, you may
use `get_exception` to get more detailed error information.

Since 1.1, if no event is passed, this method will block until the
authentication succeeds or fails.  On failure, an exception is raised.
Otherwise, the method simply returns.

If the server requires multi-step authentication (which is very rare),
this method will return a list of auth types permissible for the next
step.  Otherwise, in the normal case, an empty list is returned.

:param str username: the username to authenticate as
:param .PKey key: the private key to authenticate with
:param .threading.Event event:
    an event to trigger when the authentication attempt is complete
    (whether it was successful or not)
:return:
    `list` of auth types permissible for the next stage of
    authentication (normally empty)

:raises BadAuthenticationType: if public-key authentication isn't
    allowed by the server for this user (and no event was passed in)
:raises AuthenticationException: if the authentication failed (and no
    event was passed in)
:raises SSHException: if there was a network error

auth_interactive(self, username, handler, submethods='')

source code 

Authenticate to the server interactively.  A handler is used to answer
arbitrary questions from the server.  On many servers, this is just a
dumb wrapper around PAM.

This method will block until the authentication succeeds or fails,
peroidically calling the handler asynchronously to get answers to
authentication questions.  The handler may be called more than once
if the server continues to ask questions.

The handler is expected to be a callable that will handle calls of the
form: ``handler(title, instructions, prompt_list)``.  The ``title`` is
meant to be a dialog-window title, and the ``instructions`` are user
instructions (both are strings).  ``prompt_list`` will be a list of
prompts, each prompt being a tuple of ``(str, bool)``.  The string is
the prompt and the boolean indicates whether the user text should be
echoed.

A sample call would thus be:
``handler('title', 'instructions', [('Password:', False)])``.

The handler should return a list or tuple of answers to the server's
questions.

If the server requires multi-step authentication (which is very rare),
this method will return a list of auth types permissible for the next
step.  Otherwise, in the normal case, an empty list is returned.

:param str username: the username to authenticate as
:param callable handler: a handler for responding to server questions
:param str submethods: a string list of desired submethods (optional)
:return:
    `list` of auth types permissible for the next stage of
    authentication (normally empty).

:raises BadAuthenticationType: if public-key authentication isn't
    allowed by the server for this user
:raises AuthenticationException: if the authentication failed
:raises SSHException: if there was a network error

.. versionadded:: 1.5

set_log_channel(self, name)

source code 

Set the channel for this transport's logging. The default is ``"paramiko.transport"`` but it can be set to anything you want. (See the `.logging` module for more info.) SSH Channels will log to a sub-channel of the one specified.

:param str name: new channel name for logging

.. versionadded:: 1.1

get_log_channel(self)

source code 

Return the channel name used for this transport's logging.

:return: channel name as a `str`

.. versionadded:: 1.2

set_hexdump(self, hexdump)

source code 

Turn on/off logging a hex dump of protocol traffic at DEBUG level in
the logs.  Normally you would want this off (which is the default),
but if you are debugging something, it may be useful.

:param bool hexdump:
    ``True`` to log protocol traffix (in hex) to the log; ``False``
    otherwise.

get_hexdump(self)

source code 

Return ``True`` if the transport is currently logging hex dumps of protocol traffic.

:return: ``True`` if hex dumps are being logged, else ``False``.

.. versionadded:: 1.4

use_compression(self, compress=True)

source code 

Turn on/off compression.  This will only have an affect before starting
the transport (ie before calling `connect`, etc).  By default,
compression is off since it negatively affects interactive sessions.

:param bool compress:
    ``True`` to ask the remote client/server to compress traffic;
    ``False`` to refuse compression

.. versionadded:: 1.5.2

getpeername(self)

source code 

Return the address of the remote side of this Transport, if possible.
This is effectively a wrapper around ``'getpeername'`` on the underlying
socket.  If the socket-like object has no ``'getpeername'`` method,
then ``("unknown", 0)`` is returned.

:return:
    the address of the remote host, if known, as a ``(str, int)``
    tuple.

run(self)

source code 
Overrides: threading.Thread.run