in reply to Telnet via Perl fails
To give due credit, the above code is from a project that a friend and I work on for fun known as the Temerity Project. Though we both contributed to this script, he refined its implementation and added that awesome regular expression to check for a user's prompt type.use Net::Telnet; # initialize the telnet module my $username = 'user'; my $password = 'some_password'; my $command = 'ls -la'; print "enter the full domain name or IP of the machine that you want t +o telnet to\n"; chomp(my $host=<STDIN>); my prompt_regex = '/ .* ( \-?\@? \w*?\s? [\$#\%>~] \]? | \\\[\\e\[0m\\\] \[0m ) \s? /x'; $shell = new Net::Telnet ('Timeout'=>'7', 'Errmode'=> sub { report_error("login failure"); }, 'Prompt' => $prompt_regex ); $shell->open(Host=>$host); # opens the object $shell->login($username,$password); # login # then we issue some command with $shell->cmd("$command"); # or get the output of some command my $cmd_output = $shell->cmd("$command"); # and close the telnet object sleep 1; $shell->close; sub report_error { .... some code here to handle errors.... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Telnet via Perl fails
by eric256 (Parson) on May 23, 2004 at 05:55 UTC | |
|
Re: Re: Telnet via Perl fails
by shamala (Acolyte) on May 24, 2004 at 10:55 UTC |