Connecting Tech Pros Worldwide Forums | Help | Site Map

How to send <ESC> to a telnet server??

G520
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi

I have been getting statistical rapports from a machine via a
telnet server. Until now it has been done manually. However
I want to automate the proccess, and scedule a PHP script to
run everyday.

Using my terminal, I give the command to order a rapport,
and then press <ESC>. Then the rapport is printed out.

Using a PHP script I can order a rapport, all works fine,
except I can not get the printout. When I try to send <ESC>
the telnet server responds with "syntax fault" so
I'm not doing it right.

I have tried the following:

$do_esc=chr(27);
fputs ($fp, "$do_esc");

and

fputs ($fp, "\e");

Any ideas???



<?php
$address = '100.100.1.5024';
$port = 5000;
$fp = fsockopen($address,$port);
$s='o';
$s=fgets($fp,128); //the telnet server responds when connected
echo("<br>$s<br>");

fputs ($fp, "SOME-COMMAND"); //some command to order a rapport
$s=fgets($fp,128);
echo("<br>$s<br>"); //telnet server responds with "rapport failed" or "executed"

/*
Here the tricky part starts,
trying to get the rapport
printed out. No success so far.
To get the rapport printed out
<ESC> has to sent to the telnet
server
*/

$do_esc=chr(27);
fputs ($fp, "$do_esc"); //this does not work, trying to
//send <ESC> to the telnet server.

while (!strstr($t,'END')) { // supposed to get the printout
$t=fgets ($fp,128); // that never comes
echo("<br>$t");
}
fclose($fp);
?>

Shane Lahey
Guest
 
Posts: n/a
#2: Jul 17 '05

re: How to send <ESC> to a telnet server??


On 8 Jun 2004 04:51:44 -0700, gullia@visir.is (G520) wrote:
[color=blue]
>Hi
>
>I have been getting statistical rapports from a machine via a
>telnet server. Until now it has been done manually. However
>I want to automate the proccess, and scedule a PHP script to
>run everyday.
>
>Using my terminal, I give the command to order a rapport,
>and then press <ESC>. Then the rapport is printed out.
>
>Using a PHP script I can order a rapport, all works fine,
>except I can not get the printout. When I try to send <ESC>
>the telnet server responds with "syntax fault" so
>I'm not doing it right.
>
>I have tried the following:
>
>$do_esc=chr(27);
>fputs ($fp, "$do_esc");
>
>and
>
>fputs ($fp, "\e");
>
>Any ideas???
>
>
>
><?php
>$address = '100.100.1.5024';
>$port = 5000;
>$fp = fsockopen($address,$port);
>$s='o';
>$s=fgets($fp,128); //the telnet server responds when connected
>echo("<br>$s<br>");
>
>fputs ($fp, "SOME-COMMAND"); //some command to order a rapport
>$s=fgets($fp,128);
>echo("<br>$s<br>"); //telnet server responds with "rapport failed" or "executed"
>
>/*
>Here the tricky part starts,
>trying to get the rapport
>printed out. No success so far.
>To get the rapport printed out
><ESC> has to sent to the telnet
>server
>*/
>
>$do_esc=chr(27);
>fputs ($fp, "$do_esc"); //this does not work, trying to
> //send <ESC> to the telnet server.
>
>while (!strstr($t,'END')) { // supposed to get the printout
> $t=fgets ($fp,128); // that never comes
> echo("<br>$t");
> }
>fclose($fp);
>?>[/color]

define('ESCAPE', 0x1B);
fputs($fp, ESCAPE . "\n"); // probably needs the \n for the recieving end to process the data.
fflush($fp); // make sure the data is sent to the recieving end now...

Chung Leong
Guest
 
Posts: n/a
#3: Jul 17 '05

re: How to send <ESC> to a telnet server??



"G520" <gullia@visir.is> wrote in message
news:510cd269.0406080351.4c62611d@posting.google.c om...[color=blue]
> Hi
>
> I have been getting statistical rapports from a machine via a
> telnet server. Until now it has been done manually. However
> I want to automate the proccess, and scedule a PHP script to
> run everyday.
>
> Using my terminal, I give the command to order a rapport,
> and then press <ESC>. Then the rapport is printed out.
>
> Using a PHP script I can order a rapport, all works fine,
> except I can not get the printout. When I try to send <ESC>
> the telnet server responds with "syntax fault" so
> I'm not doing it right.
>
> I have tried the following:
>
> $do_esc=chr(27);
> fputs ($fp, "$do_esc");
>
> and
>
> fputs ($fp, "\e");
>
> Any ideas???
>
>
>
> <?php
> $address = '100.100.1.5024';
> $port = 5000;
> $fp = fsockopen($address,$port);
> $s='o';
> $s=fgets($fp,128); //the telnet server responds when connected
> echo("<br>$s<br>");
>
> fputs ($fp, "SOME-COMMAND"); //some command to order a rapport
> $s=fgets($fp,128);
> echo("<br>$s<br>"); //telnet server responds with "rapport failed" or[/color]
"executed"[color=blue]
>
> /*
> Here the tricky part starts,
> trying to get the rapport
> printed out. No success so far.
> To get the rapport printed out
> <ESC> has to sent to the telnet
> server
> */
>
> $do_esc=chr(27);
> fputs ($fp, "$do_esc"); //this does not work, trying to
> //send <ESC> to the telnet server.
>
> while (!strstr($t,'END')) { // supposed to get the printout
> $t=fgets ($fp,128); // that never comes
> echo("<br>$t");
> }
> fclose($fp);
> ?>[/color]

Telnet escape is actually ^] . Try that.


G520
Guest
 
Posts: n/a
#4: Jul 17 '05

re: How to send <ESC> to a telnet server??


Thanks guys, but I am:

WRONG – WRONG – WRONG !!!!!!!!

My terminal program translates <ESC> to <CTR>+d

So I need a way to send <CTR>+d and not <ESC> to the telnet server.

Anyone know how I can do this????
Jeppe Uhd
Guest
 
Posts: n/a
#5: Jul 17 '05

re: How to send <ESC> to a telnet server??


G520 wrote:[color=blue]
> Thanks guys, but I am:
>
> WRONG - WRONG - WRONG !!!!!!!!
>
> My terminal program translates <ESC> to <CTR>+d
>
> So I need a way to send <CTR>+d and not <ESC> to the telnet server.
>
> Anyone know how I can do this????[/color]

$ctrld=chr(4);
fwrite ($fp, $ctrld,1);

--
MVH Jeppe Uhd - NX http://nx.dk
Webhosting for nørder og andet godtfolk


G520
Guest
 
Posts: n/a
#6: Jul 17 '05

re: How to send <ESC> to a telnet server??


"Jeppe Uhd" <knewsnospam@nx.dk> wrote in message news:<m2jjp1-92v1.ln1@crm.nwg.dk>...[color=blue]
> G520 wrote:[color=green]
> > Thanks guys, but I am:
> >
> > WRONG - WRONG - WRONG !!!!!!!!
> >
> > My terminal program translates <ESC> to <CTR>+d
> >
> > So I need a way to send <CTR>+d and not <ESC> to the telnet server.
> >
> > Anyone know how I can do this????[/color]
>
> $ctrld=chr(4);
> fwrite ($fp, $ctrld,1);[/color]

Thanks Jeppe, this worked fine...
Closed Thread