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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • G520

    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($addr ess,$port);
    $s='o';
    $s=fgets($fp,12 8); //the telnet server responds when connected
    echo("<br>$s<br >");

    fputs ($fp, "SOME-COMMAND"); //some command to order a rapport
    $s=fgets($fp,12 8);
    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,'EN D')) { // supposed to get the printout
    $t=fgets ($fp,128); // that never comes
    echo("<br>$t");
    }
    fclose($fp);
    ?>
  • Shane Lahey

    #2
    Re: How to send &lt;ESC&gt; 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($addr ess,$port);
    >$s='o';
    >$s=fgets($fp,1 28); //the telnet server responds when connected
    >echo("<br>$s<b r>");
    >
    >fputs ($fp, "SOME-COMMAND"); //some command to order a rapport
    >$s=fgets($fp,1 28);
    >echo("<br>$s<b r>"); //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,'EN D')) { // 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...

    Comment

    • Chung Leong

      #3
      Re: How to send &lt;ESC&gt; to a telnet server??


      "G520" <gullia@visir.i s> wrote in message
      news:510cd269.0 406080351.4c626 11d@posting.goo gle.com...[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($addr ess,$port);
      > $s='o';
      > $s=fgets($fp,12 8); //the telnet server responds when connected
      > echo("<br>$s<br >");
      >
      > fputs ($fp, "SOME-COMMAND"); //some command to order a rapport
      > $s=fgets($fp,12 8);
      > 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,'EN D')) { // supposed to get the printout
      > $t=fgets ($fp,128); // that never comes
      > echo("<br>$t");
      > }
      > fclose($fp);
      > ?>[/color]

      Telnet escape is actually ^] . Try that.


      Comment

      • G520

        #4
        Re: How to send &lt;ESC&gt; 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????

        Comment

        • Jeppe Uhd

          #5
          Re: How to send &lt;ESC&gt; 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


          Comment

          • G520

            #6
            Re: How to send &lt;ESC&gt; to a telnet server??

            "Jeppe Uhd" <knewsnospam@nx .dk> wrote in message news:<m2jjp1-92v1.ln1@crm.nw g.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...

            Comment

            Working...