2

I am writing a php code that connects to a cisco router via ssh. I am facing a problem (returning null) when getting the interfaces' info.

Here is the code that I wrote:

$ssh = new Net_SSH2($ip);
if (!$ssh->login($user, $pass)) {
    exit('Login Failed');
}

$ssh->exec('enable');
$ssh->read('Password:');
$ssh->write("password\n");
echo $ssh->read();
$a=$ssh->exec('show run | include interface');

$a (the show command) is returning null.

Any idea?

aline
  • 27
  • 1
  • 6

1 Answers1

1

Is show run | include interface supposed to run after enable? Is Password: supposed to be a prompt of the enable command? Assuming the answers to those questions are yes and yes then I think this is more along the lines of what you're wanting to do:

$ssh->read('[prompt]');
$ssh->write("enable\n");
$ssh->read('Password:');
$ssh->write("password\n");
echo $ssh->read('[prompt]');
$ssh->write("show run | include interface\n");
echo $ssh->read('[prompt]');
neubert
  • 15,947
  • 24
  • 120
  • 212