Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 17th, 2005, 06:42 AM
G520
Guest
 
Posts: n/a
Default How to send <ESC> to a telnet server??

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);
?>
  #2  
Old July 17th, 2005, 06:42 AM
Shane Lahey
Guest
 
Posts: n/a
Default 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...

  #3  
Old July 17th, 2005, 06:42 AM
Chung Leong
Guest
 
Posts: n/a
Default 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.


  #4  
Old July 17th, 2005, 06:43 AM
G520
Guest
 
Posts: n/a
Default 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????
  #5  
Old July 17th, 2005, 06:43 AM
Jeppe Uhd
Guest
 
Posts: n/a
Default 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


  #6  
Old July 17th, 2005, 06:45 AM
G520
Guest
 
Posts: n/a
Default 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...
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles