-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathwifi_password.java
88 lines (72 loc) · 2.85 KB
/
wifi_password.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class WifiProfileReader {
public static void main(String[] args) {
try {
Process process = Runtime.getRuntime().exec("netsh wlan show profiles");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
List<String> profiles = new ArrayList<>();
while ((line = reader.readLine()) != null) {
if (line.startsWith(" All User Profile")) {
String profileName = line.substring(line.indexOf(":") + 1).trim();
profiles.add(profileName);
}
}
List<WifiProfile> wifiList = new ArrayList<>();
for (String profile : profiles) {
Process profileProcess = Runtime.getRuntime().exec("netsh wlan show profile \"" + profile + "\" key=clear");
BufferedReader profileReader = new BufferedReader(new InputStreamReader(profileProcess.getInputStream()));
String profileLine;
StringBuilder profileInfo = new StringBuilder();
while ((profileLine = profileReader.readLine()) != null) {
profileInfo.append(profileLine).append("\n");
}
if (profileInfo.toString().contains("Security key : Absent")) {
continue;
} else {
WifiProfile wifiProfile = new WifiProfile();
wifiProfile.setSsid(profile);
Pattern passwordPattern = Pattern.compile("Key Content : (.*)");
Matcher passwordMatcher = passwordPattern.matcher(profileInfo.toString());
if (passwordMatcher.find()) {
wifiProfile.setPassword(passwordMatcher.group(1));
} else {
wifiProfile.setPassword(null);
}
wifiList.add(wifiProfile);
}
}
for (WifiProfile wifiProfile : wifiList) {
System.out.println(wifiProfile);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
class WifiProfile {
private String ssid;
private String password;
public String getSsid() {
return ssid;
}
public void setSsid(String ssid) {
this.ssid = ssid;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "SSID: " + ssid + ", Password: " + password;
}
}