please help in socket_send function in php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ranishobha21@gmail.com

    #1

    please help in socket_send function in php

    Dear all,

    i want to send some unix commands to remote unix machine in france
    through php.i am using socket communication in php, i have written a
    socket communication program so that it connects to the remote
    machine.

    i dont get any errors it says socket is connected.i dont know whether
    the socket is connected or not.

    now i want to send username and password to that remote machine.i am
    using socket_send function.

    $username='abcd ';
    $output=socket_ send($socket, $username, strLen($usernam e),0);
    echo $output;

    what ever i send it returns the value integer.for example if i send
    $username ='abcd'; then it returns the length as 4,if i send abcde it
    returns 5.

    I think my username and password is not reaching to the remote machine
    when i use socket_send.

    can you please give some suggesions

    Regards
    shobha

  • Jerry Stuckle

    #2
    Re: please help in socket_send function in php

    ranishobha21@gm ail.com wrote:
    Dear all,
    >
    i want to send some unix commands to remote unix machine in france
    through php.i am using socket communication in php, i have written a
    socket communication program so that it connects to the remote
    machine.
    >
    i dont get any errors it says socket is connected.i dont know whether
    the socket is connected or not.
    >
    now i want to send username and password to that remote machine.i am
    using socket_send function.
    >
    $username='abcd ';
    $output=socket_ send($socket, $username, strLen($usernam e),0);
    echo $output;
    >
    what ever i send it returns the value integer.for example if i send
    $username ='abcd'; then it returns the length as 4,if i send abcde it
    returns 5.
    >
    I think my username and password is not reaching to the remote machine
    when i use socket_send.
    >
    can you please give some suggesions
    >
    Regards
    shobha
    >
    Hi, Shobha,

    It's hard to tell with the code you posted. Can you post the real code?
    Or, if it's large, cut it down to the bare minimum and post it?

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • ranishobha21@gmail.com

      #3
      Re: please help in socket_send function in php

      On Feb 14, 12:35 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
      ranishobh...@gm ail.com wrote:
      Dear all,
      >
      i want to send some unix commands to remote unix machine in france
      throughphp.i am using socket communication inphp, i have written a
      socket communication program so that it connects to the remote
      machine.
      >
      i dont get any errors it says socket is connected.i dont know whether
      the socket is connected or not.
      >
      now i want to send username and password to that remote machine.i am
      using socket_send function.
      >
      $username='abcd ';
      $output=socket_ send($socket, $username, strLen($usernam e),0);
      echo $output;
      >
      what ever i send it returns the value integer.for example if i send
      $username ='abcd'; then it returns the length as 4,if i send abcde it
      returns 5.
      >
      I think my username and password is not reaching to the remote machine
      when i use socket_send.
      >
      can you please give some suggesions
      >
      Regards
      shobha
      >
      Hi,Shobha,
      >
      It's hard to tell with the code you posted. Can you post the real code?
      Or, if it's large, cut it down to the bare minimum and post it?
      >
      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstuck...@attgl obal.net
      =============== ===- Hide quoted text -
      >
      - Show quoted text -
      Hi Jerry and all,

      i want to connect to a remote machine using socket programming in
      php.i have hostname,port number,username and password.how can i send
      it.i want to write a client program but unable to do it.can any one
      help me.

      Regards
      shobha

      Comment

      • Jerry Stuckle

        #4
        Re: please help in socket_send function in php

        ranishobha21@gm ail.com wrote:
        On Feb 14, 12:35 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
        >ranishobh...@g mail.com wrote:
        >>Dear all,
        >>i want to send some unix commands to remote unix machine in france
        >>throughphp. i am using socket communication inphp, i have written a
        >>socket communication program so that it connects to the remote
        >>machine.
        >>i dont get any errors it says socket is connected.i dont know whether
        >>the socket is connected or not.
        >>now i want to send username and password to that remote machine.i am
        >>using socket_send function.
        >>$username='ab cd';
        >>$output=socke t_send($socket, $username, strLen($usernam e),0);
        >>echo $output;
        >>what ever i send it returns the value integer.for example if i send
        >>$username ='abcd'; then it returns the length as 4,if i send abcde it
        >>returns 5.
        >>I think my username and password is not reaching to the remote machine
        >>when i use socket_send.
        >>can you please give some suggesions
        >>Regards
        >>shobha
        >Hi,Shobha,
        >>
        >It's hard to tell with the code you posted. Can you post the real code?
        > Or, if it's large, cut it down to the bare minimum and post it?
        >>
        >--
        >============== ====
        >Remove the "x" from my email address
        >Jerry Stuckle
        >JDS Computer Training Corp.
        >jstuck...@attg lobal.net
        >============== ====- Hide quoted text -
        >>
        >- Show quoted text -
        >
        Hi Jerry and all,
        >
        i want to connect to a remote machine using socket programming in
        php.i have hostname,port number,username and password.how can i send
        it.i want to write a client program but unable to do it.can any one
        help me.
        >
        Regards
        shobha
        >
        Shobha,

        As I said - it depends on what you're trying to do. Post a stripped
        down version of your code and we'll take a look at it.



        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • ranishobha21@gmail.com

          #5
          Re: please help in socket_send function in php

          On Feb 16, 2:10 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
          ranishobh...@gm ail.com wrote:
          On Feb 14, 12:35 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
          ranishobh...@gm ail.com wrote:
          >Dear all,
          >i want to send some unix commands to remote unix machine in france
          >throughphp.i am using socket communication inphp, i have written a
          >socket communication program so that it connects to the remote
          >machine.
          >i dont get any errors it says socket is connected.i dont know whether
          >the socket is connected or not.
          >now i want to send username and password to that remote machine.i am
          >using socket_send function.
          >$username='abc d';
          >$output=socket _send($socket, $username, strLen($usernam e),0);
          >echo $output;
          >what ever i send it returns the value integer.for example if i send
          >$username ='abcd'; then it returns the length as 4,if i send abcde it
          >returns 5.
          >I think my username and password is not reaching to the remote machine
          >when i use socket_send.
          >can you please give some suggesions
          >Regards
          >>shobha
          Hi,Shobha,
          >
          It's hard to tell with the code you posted. Can you post the real code?
          Or, if it's large, cut it down to the bare minimum and post it?
          >
          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstuck...@attgl obal.net
          =============== ===- Hide quoted text -
          >
          - Show quoted text -
          >
          Hi Jerry and all,
          >
          i want to connect to a remote machine using socket programming in
          php.i have hostname,port number,username and password.how can i send
          it.i want to write a client program but unable to do it.can any one
          help me.
          >
          Regards
          shobha
          >
          Shobha,
          >
          As I said - it depends on what you're trying to do. Post a stripped
          down version of your code and we'll take a look at it.
          >
          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstuck...@attgl obal.net
          =============== ===- Hide quoted text -
          >
          - Show quoted text -

          Dear Jerry,

          I am sending the code below.i have not specifies the host name.i want
          to send command to server and get the response from it.but it doesnt
          work.when i connect with the telnet using ssh to remote machine it
          works.

          i type telnet hostname->username->password and then i can login to the
          remote machine.how can i send hostname with username and password to
          remote machine.

          <?php


          $cmnd= "abc";
          $host="....";
          $port="12345";
          $socket = socket_create(A F_INET, SOCK_STREAM, SOL_TCP) ;
          socket_connect( $socket,$host,$ port) ;


          socket_write($s ocket, $cmnd) ;

          $ser_messegeg=s ocket_read ($socket, 1024);
          echo $ser_messege;
          socket_close($s ocket) ;
          }
          ?>


          Please help me

          Regards
          Irfan

          Comment

          • Jerry Stuckle

            #6
            Re: please help in socket_send function in php

            ranishobha21@gm ail.com wrote:
            On Feb 16, 2:10 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
            >ranishobh...@g mail.com wrote:
            >>On Feb 14, 12:35 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
            >>>ranishobh... @gmail.com wrote:
            >>>>Dear all,
            >>>>i want to send some unix commands to remote unix machine in france
            >>>>throughphp. i am using socket communication inphp, i have written a
            >>>>socket communication program so that it connects to the remote
            >>>>machine.
            >>>>i dont get any errors it says socket is connected.i dont know whether
            >>>>the socket is connected or not.
            >>>>now i want to send username and password to that remote machine.i am
            >>>>using socket_send function.
            >>>>$username=' abcd';
            >>>>$output=soc ket_send($socke t, $username, strLen($usernam e),0);
            >>>>echo $output;
            >>>>what ever i send it returns the value integer.for example if i send
            >>>>$username ='abcd'; then it returns the length as 4,if i send abcde it
            >>>>returns 5.
            >>>>I think my username and password is not reaching to the remote machine
            >>>>when i use socket_send.
            >>>>can you please give some suggesions
            >>>>Regards
            >>>>shobha
            >>>Hi,Shobha,
            >>>It's hard to tell with the code you posted. Can you post the real code?
            >>> Or, if it's large, cut it down to the bare minimum and post it?
            >>>--
            >>>============ ======
            >>>Remove the "x" from my email address
            >>>Jerry Stuckle
            >>>JDS Computer Training Corp.
            >>>jstuck...@at tglobal.net
            >>>============ ======- Hide quoted text -
            >>>- Show quoted text -
            >>Hi Jerry and all,
            >>i want to connect to a remote machine using socket programming in
            >>php.i have hostname,port number,username and password.how can i send
            >>it.i want to write a client program but unable to do it.can any one
            >>help me.
            >>Regards
            >>shobha
            >Shobha,
            >>
            >As I said - it depends on what you're trying to do. Post a stripped
            >down version of your code and we'll take a look at it.
            >>
            >--
            >============== ====
            >Remove the "x" from my email address
            >Jerry Stuckle
            >JDS Computer Training Corp.
            >jstuck...@attg lobal.net
            >============== ====- Hide quoted text -
            >>
            >- Show quoted text -
            >
            >
            Dear Jerry,
            >
            I am sending the code below.i have not specifies the host name.i want
            to send command to server and get the response from it.but it doesnt
            work.when i connect with the telnet using ssh to remote machine it
            works.
            >
            i type telnet hostname->username->password and then i can login to the
            remote machine.how can i send hostname with username and password to
            remote machine.
            >
            <?php
            >
            >
            $cmnd= "abc";
            $host="....";
            $port="12345";
            $socket = socket_create(A F_INET, SOCK_STREAM, SOL_TCP) ;
            socket_connect( $socket,$host,$ port) ;
            >
            >
            socket_write($s ocket, $cmnd) ;
            >
            $ser_messegeg=s ocket_read ($socket, 1024);
            echo $ser_messege;
            socket_close($s ocket) ;
            }
            ?>
            >
            >
            Please help me
            >
            Regards
            Irfan
            >
            Irfan,

            Well, first of all, you need to use the correct port i.e. telnet would
            be port 23.

            Second, I think you mean just send the username and password. You don't
            send the hostname - you specify it in the socket_connect call.

            And when you connect, you should get a prompt to log in. You need to
            read from the socket to get that prompt, then send your user id to the
            socket. Wait for the password prompt and send your password. And so on.

            Is this clearer?

            P.S. Please don't multi-post.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            Working...