From cfe9e327eb2dcc1d6ae7930b4c54b8b5201e76c9 Mon Sep 17 00:00:00 2001 From: Armando Ceballos Date: Wed, 24 May 2023 20:37:35 -0600 Subject: [PATCH] Password igual con expresion regular --- app/Commands/Redes_wifi.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app/Commands/Redes_wifi.php b/app/Commands/Redes_wifi.php index 4f81a45..cd3df8a 100644 --- a/app/Commands/Redes_wifi.php +++ b/app/Commands/Redes_wifi.php @@ -40,19 +40,33 @@ class Redes_wifi extends Command foreach ($profiles as $profile) { $linea = "[{$profile}] "; if (!$this->option('list')) - $linea .= $this->getPassword($profile); + $linea .= $this->getPasswordRegex($profile); $this->line($linea); } } public function getProfilesRegex() { - $result = Process::run('netsh wlan show profile'); - $salidaprofiles = $result->output(); - //$salidaprofiles = file_get_contents('profiles.txt'); + /*$result = Process::run('netsh wlan show profile'); + $salidaprofiles = $result->output();*/ + $salidaprofiles = file_get_contents('profiles.txt'); preg_match_all("/: \s*(.*)/", $salidaprofiles, $profiles); return $profiles[1]; } + + public function getPasswordRegex($profile) + { + $result = Process::run("netsh wlan show profile \"{$profile}\" key=clear"); + $salidapassword = $result->output(); + if (str_contains($salidapassword, "No hay ninguna interfaz inalámbrica en el sistema.")) { //Esto evita que ejecute regex si hay fallo + $this->error("Fallo al ejecutar comando de password"); + die(); + } + //$salidapassword = file_get_contents('prueba.txt'); + preg_match_all("/Contenido de la clave\s*:\s*(\S+)/", $salidapassword, $password); + return $password[1][0]; + } + public function getProfiles() { $result = Process::run('netsh wlan show profile');