Hi, I am trying to write a script that will connect to the telnet port on my device, send a command, and get the reply back. My script is currently not returning the result of the command I send.
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket;
my ($host, $port) = ('111.111.111.111', '23');
my $command = "\$TEMP*";
my $socket = new IO::Socket::INET (
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp',
);
if (!$socket) {
die "Unable to establish connection to $host\n";
}
print $socket $command;
$socket->getline;
my $output = <$socket>;
$socket->close;
print "$output\n";
So the script is suppose to open a socket on port 23, send the command $TEMP* and then get the result that the device will give. The script either hangs or it just returns the "Welcome to device 'devicename', please input your commands".
Is there anyway to make the script wait and grab the output after the command $TEMP* is input? The device is suppose to return something like $TEMP*,42C.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.