Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2.  
  3. function ros_connect($host, $port, $username, $password) {
  4. if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
  5. $methods = array ( 'kex' => 'diffie-hellman-group1-sha1' );
  6. $shell = ssh2_connect($host, $port, $methods);
  7. ssh2_auth_password($shell, $username, $password);
  8. return $shell;
  9. }
  10.  
  11. function ros_command($shell, $command) {
  12. $buffer = "";
  13. $data = "";
  14. $stream = ssh2_exec($shell, $command);
  15. stream_set_blocking( $stream, true );
  16. while( $buffer = fread($stream, 4096) ) {
  17. $data .= $buffer;
  18. }
  19. fclose($stream);
  20. return $data;
  21. }
  22. $ips = array(
  23. "74.254.202.6",
  24. "74.254.202.7",
  25. "74.254.202.9",
  26. "74.254.202.13",
  27. "74.254.202.15",
  28. "74.254.202.16",
  29. "74.254.202.17",
  30. "74.254.202.18",
  31. "74.254.202.19",
  32. "74.254.202.20",
  33. "74.254.202.21",
  34. "74.254.202.22",
  35. "74.254.202.23",
  36. "74.254.202.24",
  37. "74.254.202.25",
  38. "74.254.202.26",
  39. "74.254.202.27",
  40. "74.254.202.28",
  41. "74.254.202.31",
  42. "74.254.202.32",
  43. "74.254.202.35",
  44. "74.254.202.36",
  45. "74.254.202.37",
  46. "74.254.202.38",
  47. "74.254.202.39",
  48. "74.254.202.41",
  49. "74.254.202.42",
  50. "74.254.202.43",
  51. "74.254.202.44",
  52. "74.254.202.45",
  53. "74.254.202.46",
  54. "74.254.202.47",
  55. "74.254.202.48",
  56. "74.254.202.50",
  57. "74.254.202.51",
  58. "74.254.202.54",
  59. "74.254.202.55",
  60. "74.254.202.56",
  61. "74.254.202.57",
  62. "74.254.202.59",
  63. "74.254.202.61"
  64. );
  65.  
  66. $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";
  67. //$cmd1= "/ip dhcp-client renew [find]";
  68.  
  69. foreach($ips as $ip) {
  70. if($ip == "") continue;
  71. echo "- $ip - ";
  72. $shell = @ros_connect($ip, "22", "admin", "password");
  73. if($shell) {
  74. $data = ros_command($shell, $cmd1);
  75. } else {
  76. unset($data);
  77. echo("Failed to connect to $ip");
  78. $ar[] = $ip;
  79. }
  80.  
  81. if($data) { echo $data; }
  82. echo "------------ end $ip ---------\n\n";
  83. }
  84. print_r($ar);
  85.