-
Notifications
You must be signed in to change notification settings - Fork 6
/
getToken.js
44 lines (40 loc) · 1.21 KB
/
getToken.js
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
const net = require('net');
if (!process.argv[2]) {
console.log('Please supply IP as parameter!');
process.exit(-2);
}
const s = net.createConnection(23, process.argv[2], () => {
console.log('Connected.');
});
s.on('data', buffer => {
const d = buffer.toString('utf-8');
if (d.toLowerCase().includes('login:')) {
console.log('Sending login.');
s.write(Buffer.from('admin\n'));
}
if (d.toLowerCase().includes('password:')) {
console.log('Sending password.');
s.write(Buffer.from('123456\n'));
}
if (d.includes('DeviceToken')) {
const pairs = d.split(',');
for (const pair of pairs) {
const [key, value] = pair.split(':');
if (key === '"DeviceToken"') {
console.log('Got token: ' + value);
process.exit(0);
}
}
process.exit(-1);
}
if (d.includes('#')) {
console.log('Sending command.');
s.write(Buffer.from('cat /mydlink/config/device.cfg\n'));
}
});
s.on('close', () => console.log('Closed.'));
s.on('error', (e) => console.log('Error:', e));
s.on('end', () => console.log('Ended.'));
s.on('ready', () => {
console.log('Ready.');
});