- Code: Select all
function connect($host,$cmd,$username,$password) {
$host = "$host.bloombroadband.com";
$port = 23;
$timeout = 10;
$usenet = fsockopen($host,$port,$errno,$timeout);
if ($usenet) {
fputs($usenet, "$username\r\n");
fputs($usenet, "$password\r\n");
fputs($usenet, "terminal length 0\r\n");
fputs($usenet, "!BEGIN!\r\n");
fputs($usenet, "$cmd\r\n");
fputs($usenet, "!END!\r\n");
fputs($usenet, "exit\r\n");
while (!feof($usenet)) {
$lame[] = fgets($usenet, 256)."\r";
}
}
if (is_array($lame)) {
foreach($lame as $key => $line) {
$line = preg_replace('/[\r\n]/','',$line);
$lame[$key] = $line;
}
return $lame;
} else {
$out['error'] = $errno;
$out['mesg'] = "ERROR: Dont know why.";
return $out;
}
}
it would be called as such..
$config_array = connect('router.mydomain.com','show running-config','username','password');
At this point, you have a cludge and a mess to deal with.. you would have to pass it through a filter, but this is why I put !BEGIN! and !END!
so, you could inevitably clean up your configuration to store it into a db like so..
- Code: Select all
foreach($config_array as $key => $line) {
if ($record !== TRUE) {
if (preg_match('/\!BEGIN\!/',$line)) {
$record = TRUE;
}
}
if (preg_match('/\!END\!/',$line)) {
$record = FALSE;
}
if ($record === TRUE) {
$array[] = $line;
}
}
unset($array['0']); // this will be the command you asked for

