SSH connection script connecting to Cisco devices

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

    SSH connection script connecting to Cisco devices

    Hello,

    I have been looking around the net for a script to help me connect to and
    help gather information from Cisco routers/switches. I have pieced together
    a couple of different scripts from various different sources. I am having
    issue when connecting to Cisco devices. For some reason the scripts
    timesout/stops working just after the connection section of the script. It
    does not give me a confirmation of completeion nor does it give me an error.
    Since this same script works when connecting to any linux computer. I assume
    the code is working correctly. I also assume that I am leaving out an
    important piece of code out due to it not working properly when connecting
    to a cisco device.

    Anyone able to give advise, or direction on this? Any help would be greatly
    appreciated.

    Thanks,

    dsx


    --------------------------------------------------------------
    <?
    include("/var/www/config_files/config.inc");
    ?>

    <html>
    <head><?=$css;? ></head>
    <body>
    <center><h3>Net Miner</h3></center><br>

    <FORM METHOD="post" ACTION="<?=$_SE RVER["PHP_SELF"];?>">
    <b>Hostname: </b><input type=text name=host value="">
    <INPUT NAME="reset" TYPE="reset" VALUE="Reset">< INPUT NAME="submit"
    TYPE="submit" VALUE="Check Device">
    </form>
    <hr>

    <?
    if($_POST["submit"]){

    $host = $_POST['host'];

    echo "<b>Host:</b> <font color=green><b>[$host]... </b></font>";

    echo "<b>Connect ion </b>";

    if (!($resource=@s sh2_connect($ho st, 22))) {
    echo "<font color=red><b>[FAILED]</b>... ";
    exit(1);
    } // End if
    echo "<font color=green><b>[ok]</b></font>... ";

    echo "<b>Authenticat ion </b>";
    if (!@ssh2_auth_pa ssword($resourc e,"USERNAME","P ASSWORD")) {
    echo "<font color=red><b>[FAILED]</b></font>... ";
    exit(1);
    }
    echo "<font color=green><b>[ok]</b></font>... ";

    // We need a shell
    echo "<b>Shell </b>";
    if (!($stdio = @ssh2_shell($re source,"xterm") )) {
    echo "<font color=red><b>[FAILED]</b></font>... ";
    exit(1);
    }
    echo "<font color=green><b>[ok]</b></font>... ";

    // Execution of any command
    echo "<b>Command Execution </b>";
    $command = "show cdp neighbors | include domainname.com\ n";
    fwrite($stdio,$ command);
    sleep(1);
    echo "<font color=green><b>[ok]</b></font>... <br /><hr><br />";


    while($line = fgets($stdio)) {
    flush();
    ob_flush();

    $array[] = chop($line);

    if (eregi('eastlin k.ca', $array[$i])) {
    if (!eregi('includ e eastlink.ca', $array[$i])) {
    if ($array[$i] != $host) {
    echo "<a href=\"get_cdp. php?host=$array[$i]\"
    target=_blank>" .$array[$i]."</a><br>";
    } // end if
    } // end if
    } // end if

    $i++;
    } // End while

    fclose($stdio);
    } // End if
    ?>
    </body>
    </html>



Working...