PDA

View Full Version : cgi script using telnet.pm not printing


wirechild
07-25-2004, 04:39 AM
I have a form that takes a couple IP address's and post them to a CGI script. One of the IP's is the router to Telnet to and the other is the host to ping form that router. This part works correclty however the output of the ping is not displayed in the browser. Can someone please help me? Here is contents of all the files and the final page. I can verify on the router that the telnet and ping is working correctly using debug commands I can see what is happening.


HTML Form:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>

<body>
<form method="post" action="/cgi-bin/form.cgi">
<h2>This is a test!</h2>

<br>
Enter Router to Ping from:
<input type="text" name="ip">
<BR>
Enter Address to Ping:
<input type="text" name="ping">
<br>
<input type="submit" value="Submit">


</form>


</body>
</html>


CGI Script named form.cgi

#!c:\Perl\bin\perl.exe -w
use CGI;
use Net::Telnet;

$form = new CGI;

#$command = $form->param('command');
#$router = $form->param('router');
$ping = $form->param('ping');
$ip = $form->param('ip');

$t = new Net::Telnet->new(Host=>$ip, Port=>23, Errmode=>'return');
$t->waitfor('termserv>');
@return = $t->cmd("ping $ping");
#$t->waitfor(String => 'termserv>');
$t->close();
print $form->header();


print $form->start_html(
-title=>'LG',
-BGCOLOR=>'white');
print "You asked me to telnet to <strong>$ip</strong> and Ping <strong>$ping</strong>\n";
print "<PRE>\n";
print "@return<BR>\n";
print "</PRE>\n";
print "<br><br>\n";
#print $t->cmd($_);
print "Thanks\n";


print $form->end_html();


Output webpage(What actually gets printed):

You asked me to telnet to 192.168.0.101 and Ping 192.168.0.1




Thanks



As you can see I am looking for @return to be printed to the page and it is not.

Calilo
07-26-2004, 11:12 PM
Well the script looks good for me, the truth i have never net::telnet, i read the telnet.pm manuals and for that it seems to be ok. but i just could not found anything about ping, so my guess would be that what might be wrong is on this line:
@return = $t->cmd("ping $ping");

maybe it should be diferent in order to retrive the info and store it in the array. but as i sadi ive never used telnet.pm but the script looks good, and if it is actually doing the ping, then the error is just in when it retrives the info.

good luck
calilo