-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetWifiPass.cpp
executable file
·60 lines (48 loc) · 1.31 KB
/
getWifiPass.cpp
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
#include <iostream>
#include <cstdio>
#include <memory>
#include <stdexcept>
#include <string>
using namespace std;
string exec (const char* cmd) {
char buffer[128];
std::string result = "";
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
if (!pipe) throw std::runtime_error("popen() failed!");
while (!feof(pipe.get())) {
if (fgets(buffer, 128, pipe.get()) != NULL)
result = buffer;
}
return result;
}
string getSSID (string str){
str = str.replace(0,str.find(":")+2, "");
return str;
}
void output (string pass, string wifi){
system("clear");
if (wifi.empty()) {
cout << "No WiFi connection found!" << endl;
} else
if (pass.empty()){
cout << "WiFi SSID: " +wifi << "*** No password found in keychain! ***" << endl;
} else {
cout << "WiFi SSID: " +wifi << "Password: " +pass;
}
}
int main(int argc, char *argv[]) {
#ifdef __APPLE__
string wifi = getSSID(exec("/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep -w SSID: "));
string cmd = "security find-generic-password -wa " + wifi + "";
output(exec(cmd.c_str()), wifi);
#endif
#ifdef _WIN32
cout << endl;
cout << "This script currently works for MacOS only :(" << endl;
cout << "Windows Version coming soon..." << endl;
cout << endl;
/*
Windows code
*/
#endif
}