telnetlib.Telnet¶
-
class
telnetlib.Telnet(host=None, port=0, timeout=<object object>)[source]¶ Telnet interface class.
An instance of this class represents a connection to a telnet server. The instance is initially not connected; the open() method must be used to establish a connection. Alternatively, the host name and optional port number can be passed to the constructor, too.
Don’t try to reopen an already connected instance.
This class has many read_*() methods. Note that some of them raise EOFError when the end of the connection is read, because they can return an empty string for other reasons. See the individual doc strings.
- read_until(expected, [timeout])
- Read until the expected string has been seen, or a timeout is hit (default is no timeout); may block.
- read_all()
- Read all data until EOF; may block.
- read_some()
- Read at least one byte or EOF; may block.
- read_very_eager()
- Read all data available already queued or on the socket, without blocking.
- read_eager()
- Read either data already queued or some data available on the socket, without blocking.
- read_lazy()
- Read all data in the raw queue (processing it first), without doing any socket I/O.
- read_very_lazy()
- Reads all data in the cooked queue, without doing any socket I/O.
- read_sb_data()
- Reads available data between SB ... SE sequence. Don’t block.
- set_option_negotiation_callback(callback)
Each time a telnet option is read on the input flow, this callback (if set) is called with the following parameters : callback(telnet socket, command, option)
option will be chr(0) when there is no option.No other action is done afterwards by telnetlib.
Methods¶
__del__() |
Destructor – close the connection. |
__init__([host, port, timeout]) |
Constructor. |
_expect_with_poll(expect_list[, timeout]) |
Read until one from a list of a regular expressions matches. |
_expect_with_select(list[, timeout]) |
Read until one from a list of a regular expressions matches. |
_read_until_with_poll(match, timeout) |
Read until a given string is encountered or until timeout. |
_read_until_with_select(match[, timeout]) |
Read until a given string is encountered or until timeout. |
close() |
Close the connection. |
expect(list[, timeout]) |
Read until one from a list of a regular expressions matches. |
fileno() |
Return the fileno() of the socket object used internally. |
fill_rawq() |
Fill raw queue from exactly one recv() system call. |
get_socket() |
Return the socket object used internally. |
interact() |
Interaction function, emulates a very dumb telnet client. |
listener() |
Helper for mt_interact() – this executes in the other thread. |
msg(msg, *args) |
Print a debug message, when the debug level is > 0. |
mt_interact() |
Multithreaded version of interact(). |
open(host[, port, timeout]) |
Connect to a host. |
process_rawq() |
Transfer from raw queue to cooked queue. |
rawq_getchar() |
Get next char from raw queue. |
read_all() |
Read all data until EOF; block until connection closed. |
read_eager() |
Read readily available data. |
read_lazy() |
Process and return data that’s already in the queues (lazy). |
read_sb_data() |
Return any data available in the SB ... |
read_some() |
Read at least one byte of cooked data unless EOF is hit. |
read_until(match[, timeout]) |
Read until a given string is encountered or until timeout. |
read_very_eager() |
Read everything that’s possible without blocking in I/O (eager). |
read_very_lazy() |
Return any data available in the cooked queue (very lazy). |
set_debuglevel(debuglevel) |
Set the debug level. |
set_option_negotiation_callback(callback) |
Provide a callback function called after each receipt of a telnet option. |
sock_avail() |
Test whether data is available on the socket. |
write(buffer) |
Write a string to the socket, doubling any IAC characters. |