<?php
function ros_connect($host, $port, $username, $password) {
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
$methods = array ( 'kex' => 'diffie-hellman-group1-sha1' );
$shell = ssh2_connect($host, $port, $methods);
ssh2_auth_password($shell, $username, $password);
return $shell;
}
function ros_command($shell, $command) {
$buffer = "";
$data = "";
$stream = ssh2_exec($shell, $command);
stream_set_blocking( $stream, true );
while( $buffer = fread($stream, 4096) ) {
$data .= $buffer;
}
fclose($stream);
return $data;
}
$ips = array(
"74.254.202.6",
"74.254.202.7",
"74.254.202.9",
"74.254.202.13",
"74.254.202.15",
"74.254.202.16",
"74.254.202.17",
"74.254.202.18",
"74.254.202.19",
"74.254.202.20",
"74.254.202.21",
"74.254.202.22",
"74.254.202.23",
"74.254.202.24",
"74.254.202.25",
"74.254.202.26",
"74.254.202.27",
"74.254.202.28",
"74.254.202.31",
"74.254.202.32",
"74.254.202.35",
"74.254.202.36",
"74.254.202.37",
"74.254.202.38",
"74.254.202.39",
"74.254.202.41",
"74.254.202.42",
"74.254.202.43",
"74.254.202.44",
"74.254.202.45",
"74.254.202.46",
"74.254.202.47",
"74.254.202.48",
"74.254.202.50",
"74.254.202.51",
"74.254.202.54",
"74.254.202.55",
"74.254.202.56",
"74.254.202.57",
"74.254.202.59",
"74.254.202.61"
);
$cmd1 = "/ip dhcp-server network set [/ip dhcp-server network find gateway=192.168.200.1] dns-server=208.67.222.222,208.67.220.220; /ip dhcp-server network print detail";
//$cmd1= "/ip dhcp-client renew [find]";
foreach($ips as $ip) {
if($ip == "") continue;
echo "- $ip - ";
$shell = @ros_connect($ip, "22", "admin", "password");
if($shell) {
$data = ros_command($shell, $cmd1);
} else {
unset($data);
echo("Failed to connect to $ip");
$ar[] = $ip;
}
if($data) { echo $data; }
echo "------------ end $ip ---------\n\n";
}
print_r($ar);