|
Posted by NewsReader on 10/22/68 11:34
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>NetMiner</h3></center><br>
<FORM METHOD="post" ACTION="<?=$_SERVER["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>Connection </b>";
if (!($resource=@ssh2_connect($host, 22))) {
echo "<font color=red><b>[FAILED]</b>... ";
exit(1);
} // End if
echo "<font color=green><b>[ok]</b></font>... ";
echo "<b>Authentication </b>";
if (!@ssh2_auth_password($resource,"USERNAME","PASSWORD")) {
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($resource,"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('eastlink.ca', $array[$i])) {
if (!eregi('include 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>
Navigation:
[Reply to this message]
|