Add remaining project files (exclude ignored folders)
This commit is contained in:
Vendored
+74
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
require 'autoload.php'; // Memuat autoload Composer
|
||||
|
||||
use phpseclib3\Net\SSH2;
|
||||
|
||||
$deviceIp = '136.1.1.100';
|
||||
$username = 'zte';
|
||||
$password = 'zte'; // Ganti dengan password yang sesuai
|
||||
$enablePassword = 'zxr10'; // Ganti dengan password untuk enable
|
||||
$port = 22; // Ganti dengan port SSH yang sesuai
|
||||
|
||||
try {
|
||||
$ssh = new SSH2($deviceIp, $port);
|
||||
$ssh->setTimeout(10); // 10 detik
|
||||
|
||||
if (!$ssh->login($username, $password)) {
|
||||
throw new Exception('Login gagal. Periksa username dan password.');
|
||||
}
|
||||
|
||||
// echo "Koneksi berhasil ke OLT ZTE.\n";
|
||||
|
||||
// Kirim perintah enable
|
||||
$ssh->write("enable\n");
|
||||
usleep(300000); // Tunggu respons 0.3 detik
|
||||
|
||||
// Kirim password untuk enable
|
||||
$ssh->write("$enablePassword\n");
|
||||
usleep(300000); // Tunggu respons 0.3 detik
|
||||
|
||||
// Jalankan perintah untuk menampilkan konfigurasi ONU
|
||||
$ssh->write("config t\n");
|
||||
usleep(300000); // Tunggu respons 0.3 detik
|
||||
|
||||
$ssh->write("show running-config interface gpon-olt_1/1/1\n");
|
||||
usleep(300000); // Tunggu respons 0.3 detik
|
||||
|
||||
$ssh->write(" ");
|
||||
usleep(300000); // Tunggu respons 0.3 detik
|
||||
|
||||
// Ambil output
|
||||
$output = $ssh->read();
|
||||
|
||||
// Tampilkan output
|
||||
// echo "Output: " . htmlspecialchars($output);
|
||||
|
||||
// Buat array dari "onu 1" hingga "onu 40"
|
||||
$allOnu = [];
|
||||
for ($i = 1; $i <= 64; $i++) {
|
||||
$allOnu[] = "onu $i";
|
||||
}
|
||||
|
||||
// Temukan semua "onu" yang ada dalam string $data
|
||||
preg_match_all('/onu \d+/', $output, $matches);
|
||||
$dataArray = $matches[0];
|
||||
|
||||
// Cari mana yang tidak ada di dalam $data
|
||||
$missingOnu = array_diff($allOnu, $dataArray);
|
||||
|
||||
// Tampilkan hasil
|
||||
foreach ($missingOnu as $onu) {
|
||||
echo "$onu tidak ada di string.<br>";
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
// echo 'Terjadi kesalahan: ' . htmlspecialchars($e->getMessage());
|
||||
} finally {
|
||||
if (isset($ssh) && $ssh->isConnected()) {
|
||||
$ssh->disconnect();
|
||||
// echo "Koneksi terputus.\n";
|
||||
} else {
|
||||
// echo "Koneksi tidak berhasil.\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user