Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8848859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:30:07+00:00 2026-06-14T12:30:07+00:00

i’m trying to use phpseclib’s NET_SSH2 library to connect to an HP switch. just

  • 0

i’m trying to use phpseclib’s NET_SSH2 library to connect to an HP switch.
just to test / get started, i’m trying to log on, and then run a ‘show interfaces brief’ command on the switch.
But after it logs me on, i get an error message :

 SSH command execution is not supported. 

here’s the code:

<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '../phpseclib');
include('Net/SSH2.php');
define('NET_SSH2_LOGGING', true); //turn on logging.

$ssh = new Net_SSH2('10.10.10.10'); //starting the ssh connection to localhost
if (!$ssh->login('', 'password')) { //if you can't log on...
  exit('Login Failed');
}
else  {
echo 'logged in<br>';
}
echo 'Attempting command: <br>';
$output = $ssh->exec('show interfaces brief');    
echo $output.'<br>';
echo 'Error message is: <br>';
$log = $ssh->getLog(NET_SSH2_LOG_COMPLEX);
foreach ($log as $logitem)  {
echo $logitem.'<br>';
}
?>

The output that this returns is:

 logged in
 Attempting command:

 Notice: Connection closed prematurely in /var/www/phpseclib/Net/SSH2.php on line 1941
 SSH command execution is not supported.
 Error message is:
 <-
 ->
 <- NET_SSH2_MSG_KEXINIT (0.0015s)
 -> NET_SSH2_MSG_KEXINIT (0s)
 -> NET_SSH2_MSG_KEXDH_INIT (0s)
 <- NET_SSH2_MSG_KEXDH_REPLY (0.5123s)
 -> NET_SSH2_MSG_NEWKEYS (0s)
 <- NET_SSH2_MSG_NEWKEYS (0s)
 -> NET_SSH2_MSG_SERVICE_REQUEST (0s)
 <- NET_SSH2_MSG_SERVICE_ACCEPT (0.1962s)
 -> NET_SSH2_MSG_USERAUTH_REQUEST (0.0001s)
 <- NET_SSH2_MSG_USERAUTH_BANNER (0.0014s)
 <- NET_SSH2_MSG_USERAUTH_SUCCESS (0.0392s)
 -> NET_SSH2_MSG_CHANNEL_OPEN (0s)
 <- NET_SSH2_MSG_CHANNEL_OPEN_CONFIRMATION (0.0204s)
 -> NET_SSH2_MSG_CHANNEL_REQUEST (0s)
 <- NET_SSH2_MSG_CHANNEL_SUCCESS (0.1011s)
 <- NET_SSH2_MSG_CHANNEL_DATA (0s)
 -> NET_SSH2_MSG_CHANNEL_DATA (0s)
 <- NET_SSH2_MSG_CHANNEL_EOF (0s)
 <- NET_SSH2_MSG_CHANNEL_REQUEST (0s)
 <- NET_SSH2_MSG_CHANNEL_CLOSE (0s)

 Notice: Connection closed prematurely in /var/www/phpseclib/Net/SSH2.php on line 1941

Line 1941 in ssh2.php is the “user_error” line you see below:

 function _send_binary_packet($data)
{
    if (feof($this->fsock)) {
        user_error('Connection closed prematurely', E_USER_NOTICE);
        return false;
    }

What I’ve done so far:

  1. I’ve logged in manually via ssh and made sure that I can run the same command.
  2. i’ve gone through the switch’s web config page to make sure there’s nothing else I need to turn on etc. for ssh.
  3. I’ve been checking phpseclib’s forums for any similar issues.

I’m using version 1.53 2010/10/24 01:24:30 of the phpseclib.

Any help would be appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:30:08+00:00Added an answer on June 14, 2026 at 12:30 pm

    You aren’t able to use the exec command on HP Procurve Switches. You have to emulate an interactive shell (unfortunately).

    Here is something I’ve made in order to basically have a batch console in order to configure more than one switch at a time. I’d put a list of IP addresses in a file called switches.txt, separating each address with a new line (be sure to leave a new line at the end of the file as well). It’s very messy, and I only used it once and didn’t put much thought into it, but it did save me a lot of time instead of manually logging into over a hundred switches. I can’t wait until I get Procurve Manager…

    Also, I didn’t take the time to properly implement and STDOUT reading, so you cannot see any output given to the switch, but I’m sure it wouldn’t be that difficult.

    <?php
    
    require ('Net/SSH2.php');
    $cnt = 0;
    $ssh = array();
    $ips = array();
    echo "\n";
    
    $handle = fopen('switches.txt', 'r');
    while (!feof($handle)) {
        $ip = trim(fgets($handle)); 
        $ips[$cnt] = $ip;
    
        //SSH Setup
    
        $ssh[$cnt] = new Net_SSH2($ip);
        echo "Logging into device: ".$ip."\n";
        if (!$ssh[$cnt]->login('USERNAMEHERE', 'PASSWORDHERE')) {
            exit ('Login Failed');
        }
        $cnt++;
    
    }
    fclose($handle);
    
    //Initial Post Login Setup
    sleep(1);
    for ($i=0; $i<sizeof($ssh); $i++) {
    echo "Performing Post Login Setup (1/2) on device: ".$ips[$i]."\n";
    $ssh[$i]->write("\n");
    }
    sleep(1);
    for ($i=0; $i<sizeof($ssh); $i++) {
    echo "Performing Post Login Setup (2/2) on device: ".$ips[$i]."\n";
    $ssh[$i]->write("conf\n");
    }
    sleep(1);
    
    
    //Command Loop
    while (true) {
        //Device Loop
        echo "\nBatch Input# ";
        $in = fopen('php://stdin', 'r');
        $buffer = fgets($in);
        for ($i=0; $i<sizeof($ssh); $i++) {
            $ssh[$i]->write($buffer);
            //echo "Wrinting command: $buffer  ;  To Device: ".$ips[$i].";\n";
        }   
    }
    fclose($handle);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.