-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.h
223 lines (203 loc) · 5.4 KB
/
data.h
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include <cstdlib>// For several general-purpose functions
#include <fstream> // For file handling
#include <iomanip> // For formatted output
#include <cstring>
#include <iostream> // For cin, cout, and system
#include <string> // For string data type
#include <locale>
#include <cmath>
#include <sstream>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <time.h>
using namespace std;
int filenumber = 0;
class apscan{
string mac;
//int mac[6]; //fuck that
string wfinterface;
string ssid;
int dBm;
int ms;
bool assoc;
time_t timescanned;
public:
string getmac(){
return mac;
}
apscan(){
}
apscan(string a, string wfinter, string ap, int db, int m, bool asoc){
mac = a;
ssid = ap;
dBm = db;
ms = m;
assoc = asoc;
}
void setfreq(int x){
dBm = x;
}
void setmac(string a){
mac = a;
}
void settimenow(){
time(×canned);
}
void setms(int x){
ms = x;
}
void setasoc(bool x){
assoc = x;
}
void setssid(string x){
ssid = x;
}
void write(string a){
ofstream file;
file.open(a, ios_base::app);
stringstream date;
date << timescanned;
string appendstring = mac + " " + ssid + " " + to_string(dBm) + " " + to_string(ms) + " " + to_string(assoc) + " " + date.str() + "\n";
file << appendstring;
file.close();
cout << "wrote";
}
};
inline bool isInteger(const std::string & s)
{
if(s.empty() || ((!isdigit(s[0])) && (s[0] != '-') && (s[0] != '+'))) return false ;
char * p ;
strtol(s.c_str(), &p, 10) ;
return (*p == 0) ;
}
/* Remember the effective and real UIDs. */
static uid_t euid, ruid;
/* Restore the effective UID to its original value. */
void do_setuid (void)
{
int status;
#ifdef _POSIX_SAVED_IDS
status = seteuid (euid);
#else
status = setreuid (ruid, euid);
#endif
if (status < 0) {
fprintf (stderr, "Couldn't set uid.\n");
exit (status);
}
}
/* Set the effective UID to the real UID. */
void undo_setuid (void)
{
int status;
#ifdef _POSIX_SAVED_IDS
status = seteuid (ruid);
#else
status = setreuid (euid, ruid);
int status;
#endif
if (status < 0) {
fprintf (stderr, "Couldn't set uid.\n");
exit (status);
}
}
/* Main program. */
void buildscan(){
//system("make all");
}
//////////////////////////////////////////////////////////////////////
int scan(string second = "wpa0", string scanname = "last_scan.txt", string project = "default_project.txt")
{
cout << "scanstart";
/* Remember the real and effective user IDs. */
//ostringstream oss;
//oss << "sudo ./wifi-scan-all" << " wlp1s0";
ruid = getuid ();
euid = geteuid ();
fstream createfile;
createfile.open(scanname.c_str());
createfile.close();
string deletecommand = "sudo rm " + scanname;
system(deletecommand.c_str());//kill last log (wont need it)
cout << "-2";
cout << "-1";
string first = "sudo ./wifi-scan-all ";
string third = " >> ";
cout << "0";
string input = first;
cout << "1";
input.append(second); //scan() gets second as parameter runs "sudo ./wifi-scan-all >interface< >> scan.txt"
input.append(third);
input.append(scanname);
//input = "sudo ./wifi-scan-all wlp1s0 >> last_scan.txt";//debug line
cout << "2";
undo_setuid ();//are these even necessary?
do_setuid ();//?
//TOO BIG :: fixed?
cout << "prescan";
system(input.c_str());//make new scan
string s;
int scanned = 0;
ifstream in;
in.close();
fstream stored;
stored.open(scanname);
cout << scanned;
string line;
cout << "\n";
cout << "prefor";
for (scanned = 0; getline(stored, s); scanned++); //counts lines of scan
stored.close();
stored.open(scanname);
cout << "between fors\n";
for(int i = 0; i < scanned;i++){
string store;
apscan objstore;
stored >> store;
objstore.setmac(store);
stored >> store;
bool wasssid = false;
string fullssid;
cout << "prewhile\n";
for (int i = 0; i<17;i++){//trying to replace broken while
if(!isInteger(store)){
if (wasssid) fullssid = fullssid + " ";
fullssid = fullssid+store;
cout << store << endl;
stored >> store;
wasssid = true;
}
if(isInteger(store)){
i = 17;
}
}
/*
while (!isInteger(store)){
if (wasssid) fullssid = fullssid + " ";
fullssid = fullssid+store;
stored >> store;
wasssid = true;
}
*/
cout << "post\n";
if (wasssid){
objstore.setssid(fullssid);
}
else{ //if the int is negative. Its a frequency? (I think)
objstore.setssid("hidden");
}
objstore.setfreq(stoi(store));
stored >> store;
objstore.setms(stoi(store));
stored >> store;
if(store == "associated") objstore.setasoc(1);
if(store == "unassociated") objstore.setasoc(0);
objstore.settimenow();
objstore.write(project);
}
cout << "a\n";
stored.close();
return scanned;
/* Do the game and record the score. */
}