Re: Howto send command over ssh using sockets

From: Date: Wed, 07 Apr 2010 15:16:03 +0000
Subject: Re: Howto send command over ssh using sockets
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-303876@lists.php.net to get a copy of this message
phpseclib does SSH without PECL extension and only with fsockopen: http://phpseclib.sourceforge.net/ On Sun Apr 4 21:09:54 2010, Hans_Åhlin wrote: > Instead of ssh, you could use telnet to connect to the Cisco router > (which incidentally runs on port 23, but is likely to be disabled on > the cisco router, unless you have a pre-SSH capable IOS running on it > (like my old cisco crap :( ) ), because i strongly doubt you have > written or are willing to write your own encryption libraries for this > project, you might also want to read IETF RFC 854 > [http://tools.ietf.org/html/rfc854] about the telnet protocol, as you > are writing your own client, and not using a pre-made one, judging > from your script. > Or if you do not like the idea of sending clear-text passwords to the > router, you might want to learn about proc_open() (or popen()) and use > the native ssh utility that most likely is present on the server, > taking great care to READ THE MANUAL for the ssh command, because you > most likely do _not_ want it to spit out ANSI-escapes to you script. > > Kind regards from > Johan Lidström > Örnsköldsvik, Sweden > irc://irc.freenode.net/Dr_Kao > frozendude+phpdev@gmail.com > > P.S. currently borrowing a friends account. > > 2010/4/5 Radek Krejča <radek.krejca@starnet.cz>: >> Hello, >> >> I am trying send command to remote host over ssh with sockets. But I need to set up >> username/password. I am trying to modify this script (from www.php.net - function fsockopen), but I >> dont know, where set username/password because I got this message: >> Bad protocol version identification 'password' from ip >> >> Library ssh2 is not currentu userfull for me, because I am not admin of server. >> >> Thank you >> Radek >> >> >> <?php >> /************************************************************ >> * Author: Richard Lajaunie >> * Mail : richard.lajaunie@cote-azur.cci.fr >> * >> * subject : this script retreive all mac-addresses on all ports >> * of a Cisco 3548 Switch by a telnet connection >> * >> * base on the script by: xbensemhoun at t-systems dot fr on the same page >> **************************************************************/ >> >> if ( array_key_exists(1, $argv) ){ >>   $cfgServer = $argv[1]; >> }else{ >>   echo "ex: 'php test.php 10.0.0.0' \n"; >>   exit; >> } >> >> $cfgPort    = 23;                //port, 22 if SSH >> $cfgTimeOut = 10; >> >> $usenet = fsockopen($cfgServer, $cfgPort, $errno, $errstr), $cfgTimeOut); >> >> if(!$usenet){ >>       echo "Connexion failed\n"; >>       exit(); >> }else{ >>       echo "Connected\n"; >>       fputs ($usenet, "password\r\n"); >>       fputs ($usenet, "en\r\n"); >>       fputs ($usenet, "password\r\n"); >>       fputs ($usenet, "sh mac-address-table\r\n"); >>       fputs ($usenet, " "); // this space bar is this for long output >> >>       // this skip non essential text >>       $j = 0; >>       while ($j<16){ >>       fgets($usenet, 128); >>       $j++; >>       } >>   stream_set_timeout($usenet, 2); // set the timeout for the fgets >>   $j = 0; >>       while (!feof($usenet)){ >>       $ret = fgets($usenet, 128); >>       $ret = str_replace("\r", '', $ret); >>       $ret = str_replace("\n", "", $ret); >>       if  (ereg("FastEthernet", $ret)){ >>           echo "$ret \n"; >>       } >>       if (ereg('--More--', $ret) ){ >>           fputs ($usenet, " "); // for following page >>       } >>       $info = stream_get_meta_data($usenet); >>       if ($info['timed_out']) { >>           $j++; >>       } >>       if ($j >2){ >>           fputs ($usenet, "lo"); >>           break; >>       } >>   } >> } >> echo "End.\r\n"; >> ?> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> >

« previous php.general (#303876) next »