Telnet - staffcheck/api GitHub Wiki
Telnet class
Used to execute remote commands via telnet connection Usess sockets functions and fgetc() to process result
All methods throw Exceptions on error
Written by Dalibor Andzakovic [email protected] Based on the code originally written by Marc Ennaji and extended by Matthias Blaser [email protected]
- Class name: Telnet
- Namespace:
const TELNET_ERROR = FALSE
const TELNET_OK = TRUE
private mixed $host
- Visibility: private
private mixed $port
- Visibility: private
private mixed $timeout
- Visibility: private
private mixed $socket = NULL
- Visibility: private
private mixed $buffer = NULL
- Visibility: private
private mixed $prompt
- Visibility: private
private mixed $errno
- Visibility: private
private mixed $errstr
- Visibility: private
private mixed $NULL
- Visibility: private
private mixed $DC1
- Visibility: private
private mixed $WILL
- Visibility: private
private mixed $WONT
- Visibility: private
private mixed $DO
- Visibility: private
private mixed $DONT
- Visibility: private
private mixed $IAC
- Visibility: private
void Telnet::__construct(string $host, integer $port, integer $timeout)
Constructor. Initialises host, port and timeout parameters defaults to localhost port 23 (standard telnet port)
- Visibility: public
- $host string - Host name or IP addres
- $port integer - TCP port number
- $timeout integer - Connection timeout in seconds
void Telnet::__destruct()
Destructor. Cleans up socket connection and command buffer
- Visibility: public
boolean Telnet::connect()
Attempts connection to remote host. Returns TRUE if sucessful.
- Visibility: public
boolean Telnet::disconnect()
Closes IP socket
- Visibility: public
string Telnet::exec(string $command)
Executes command and returns a string with result.
This method is a wrapper for lower level private methods
- Visibility: public
- $command string - Command to execute
boolean Telnet::login(string $username, string $password, $login_prompt, $password_prompt, $prompt)
Attempts login to remote host.
This method is a wrapper for lower level private methods and should be modified to reflect telnet implementation details like login/password and line prompts. Defaults to standard unix non-root prompts
- Visibility: public
- $username string - Username
- $password string - Password
- $login_prompt mixed
- $password_prompt mixed
- $prompt mixed
boolean Telnet::setPrompt(string $s)
Sets the string of characters to respond to.
This should be set to the last character of the command line prompt
- Visibility: public
- $s string - String to respond to
boolean|string|void Telnet::getc()
Gets character from the socket
- Visibility: private
void Telnet::clearBuffer()
Clears internal command buffer
- Visibility: private
boolean Telnet::readTo(string $prompt)
Reads characters from the socket and adds them to command buffer.
Handles telnet control characters. Stops when prompt is ecountered.
- Visibility: private
- $prompt string
boolean Telnet::write(string $buffer, boolean $addNewLine)
Write command to a socket
- Visibility: private
- $buffer string - Stuff to write to socket
- $addNewLine boolean - Default true, adds newline to the command
string Telnet::getBuffer()
Returns the content of the command buffer
- Visibility: private
boolean Telnet::negotiateTelnetOptions()
Telnet control character magic
- Visibility: private
mixed Telnet::waitPrompt()
Reads socket until prompt is encountered
- Visibility: private