Query: net::telnet
OS: centos
Section: 3
Links: centos man pages all man pages
Forums: unix linux community forum categories
Format: Original Unix Latex Style Formatted with HTML and a Horizontal Scroll Bar
Net::Telnet(3) User Contributed Perl Documentation Net::Telnet(3)NAMENet::Telnet - interact with TELNET port or other TCP portsSYNOPSIS"use Net::Telnet ();" see METHODS section belowDESCRIPTIONNet::Telnet allows you to make client connections to a TCP port and do network I/O, especially to a port using the TELNET protocol. Simple I/O methods such as print, get, and getline are provided. More sophisticated interactive features are provided because connecting to a TELNET port ultimately means communicating with a program designed for human interaction. These interactive features include the ability to specify a time-out and to wait for patterns to appear in the input stream, such as the prompt from a shell. Other reasons to use this module than strictly with a TELNET port are: o You're not familiar with sockets and you want a simple way to make client connections to TCP services. o You want to be able to specify your own time-out while connecting, reading, or writing. o You're communicating with an interactive program at the other end of some socket or pipe and you want to wait for certain patterns to appear. Here's an example that prints who's logged-on to the remote host sparky. In addition to a username and password, you must also know the user's shell prompt, which for this example is "bash$" use Net::Telnet (); $t = new Net::Telnet (Timeout => 10, Prompt => '/bash$ $/'); $t->open("sparky"); $t->login($username, $passwd); @lines = $t->cmd("who"); print @lines; More examples are in the EXAMPLES section below. Usage questions should be directed to the Usenet newsgroup comp.lang.perl.modules. Contact me, Jay Rogers <jay@rgrs.com>, if you find any bugs or have suggestions for improvement. What To Know Before Using o All output is flushed while all input is buffered. Each object contains its own input buffer. o The output record separator for "print()" and "cmd()" is set to " " by default, so that you don't have to append all your commands with a newline. To avoid printing a trailing " " use "put()" or set the output_record_separator to "". o The methods "login()" and "cmd()" use the prompt setting in the object to determine when a login or remote command is complete. Those methods will fail with a time-out if you don't set the prompt correctly. o Use a combination of "print()" and "waitfor()" as an alternative to "login()" or "cmd()" when they don't do what you want. o Errors such as timing-out are handled according to the error mode action. The default action is to print an error message to standard error and have the program die. See the "errmode()" method for more information. o When constructing the match operator argument for "prompt()" or "waitfor()", always use single quotes instead of double quotes to avoid unexpected backslash interpretation (e.g. '/bash$ $/'). If you're constructing a DOS like file path, you'll need to use four backslashes to represent one (e.g. '/c:\\users\\bill>$/i'). Of course don't forget about regexp metacharacters like ".", "[", or "$". You'll only need a single backslash to quote them. The anchor metacharacters "^" and "$" refer to positions in the input buffer. To avoid matching characters read that look like a prompt, it's a good idea to end your prompt pattern with the "$" anchor. That way the prompt will only match if it's the last thing read. o In the input stream, each sequence of carriage return and line feed (i.e. "