Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Watching telnet port for data parching data and returning responce

Status
Not open for further replies.

sirjase

Technical User
Feb 1, 2005
6
US
Thank you for viewing my post. And any help would be greatly appr........
What I Would like to do is in a CGI script... I would like to open a telnet sesion with lets say 192.168.1.1 port 7011 and pass a string "do:this,now,withoutdelay,please,thankyou" and then wait for a responce to the command and send thr responce of the command to viewers browers........
Refreshing screen as new data arrives.......
 
Ok I don't Know What to do next.
Should I move this post to cgi?
I came up with this code..
Code:
my ($hostname,$port,$host,$obj,$ok);
use Net::Telnet ();
$hostname = 204.5.40.133;
$port = 9053;
#*#*#*#*#*#*# Connection #*#*#*#*#*#*#
#$obj = new Net::Telnet ();
	$host = new Net::Telnet (Timeout=>10);
    	$host->open(Host=>"data1",
                    Port=>9053);
#*#*#*#*#*#*#*#*Pass data to Switch #*#*#*#*#*#*
	#$host->cmd("op:list,trunks;");
	$host->print("op:list,tg=1911,oos;");
#*#*#*#*#*#*#*#*Display Output#*#*#*#*#
while($host){ # != "/COMPLETED/"){
	if ($obj =~ m/"COMPLETED"/)
		{print $host;
		print "The file should be done!";
		exit}
	#print $host;
it work from a command line
Code:
[u]c:>[/u] perl optest.pl
but the script doen't stop when 'COMPLETED' is displayed.
Where did I Go wrong.......
also if I place it in a CGI bin nothing happen at all when I
us my browser???
 
first off all you are missing a right curly bracket at line 19, at end of line

second what kind of remote host is the one at line 8
$host->open(Host=>"data1",

and thrird try to right your 3rd and 4th line like this
$hostname = "204.5.40.133";
$port = "9053";

and then asign it to the
Code:
$host->open(Host => $hostname,
            Port => $port
            );

also i suggest
use warnings;
use strict;

do those things and tell us how it worked

oh and another thing
put perl.exe in your path

and run your scripts like this

c:\ optest.pl

..............
 
oh and i forgot to mention the 'exit' you have

write it like this

exit 0;
 
I'm able to connect to the remote host.
And get good output.
Problem is The last word of the output is COMPLETED.
At that point I would like the connection to go away.
I still Cannot get it work thru a browser.
Thanks for your help.......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top