come ottenere la password wifi da cmd con java
Sto cercando di fornire la mia password di connessione wifi con java. ma devo farlo come amministratore.
try {
Process p = Runtime.getRuntime().exec("netsh.exe wlan show profiles name=superonline key=clear");
BufferedReader bf = new BufferedReader(new InputStreamReader(p.getInputStream()));
while (bf.readLine() != null)
System.out.println(bf.readLine());
} catch (Exception ex) {
ex.printStackTrace();
}
Quando lo provo come utente standard:
Quando lo provo come amministratore:
Come può farlo nel codice java?
0
2 answers
Usa la classe java.util.Scanner
:
Process p = Runtime.getRuntime().exec("netsh wlan show profiles name=superonline key=clear");
Scanner sc=new Scanner(p.getInputStream());
while (sc.hasNextLine()) {
System.out.println(sc.nextLine());
}
0
Author: nickkoro, 2016-02-25 18:59:11
Non è possibile ottenere questo tipo di accesso con java.
Il meglio che puoi fare è avvolgere l'output del comando in InputStream e provare a leggere i dati da lì
public static void main(String[] args) {
try {
// create a new process
System.out.println("Creating Process...");
Process p = Runtime.getRuntime().exec("netsh.exe wlan .......");
// get the input stream of the process and print it
InputStream in = p.getInputStream();
for (int i = 0; i < in.available(); i++) {
System.out.println("" + in.read());
}
// wait for 10 seconds and then destroy the process
Thread.sleep(10000);
p.destroy();
} catch (Exception ex) {
ex.printStackTrace();
}
}
0
Author: George Moralis, 2015-12-28 10:14:08