-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchmac.cpp
74 lines (61 loc) · 1.49 KB
/
chmac.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
61
62
63
64
65
66
67
68
69
70
71
72
73
// chmac.cpp : Defines the entry point for the console application.
//
#include <tchar.h>
#include "NetworkAdapter.h"
#include <iostream>
using namespace CodeProjectUtils;
ADAPTERINFO* adapters = NULL;
CNetworkAdapterList nal;
int reset(_TCHAR* str) {
int count = nal.GetCount();
for(int i = 0; i < count; i++) {
if(adapters[i].Description.find(str) == std::wstring::npos)
continue;
std::wcout << L"Resetting " << adapters[i].Description << ": " << adapters[i].MAC << L" -> ";
wchar_t &last = adapters[i].MAC.at(11);
++last;
if(last > L'F')
last = L'0';
std::wcout << adapters[i].MAC << std::endl;
if(!UpdateRegistry(adapters[i].InstanceId, adapters[i].MAC.c_str())) {
std::cout << "UpdateRegistry failed.\n";
return -3;
}
if(!Reset(&adapters[i])) {
std::cout << "Reset failed." << std::endl;
return -4;
}
std::cout << "Reset succeeded." << std::endl;
return 0;
}
return -5;
}
int _tmain(int argc, _TCHAR* argv[])
{
bool do_reset = false;
if(argc > 1)
do_reset = true;
int retval = 0;
if(!nal.IsValid()) {
retval = -1;
goto cleanup;
}
int count = nal.GetCount();
if(count <= 0) {
retval = -2;
goto cleanup;
}
adapters = new ADAPTERINFO[count];
nal.GetAdapters(adapters);
if(do_reset)
retval = reset(argv[1]);
else
for(int i=0; i<count; i++) {
std::wcout << adapters[i].InstanceId << L' ';
std::wcout << adapters[i].MAC << L' ';
std::wcout << adapters[i].Description << std::endl;
}
cleanup:
delete[]adapters;
return retval;
}