Repository navigation
Expand file tree
/
Copy pathmrstresser.js
More file actions
95 lines (77 loc) · 2.34 KB
/
Copy pathmrstresser.js
File metadata and controls
95 lines (77 loc) · 2.34 KB
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
/**
* MrStresser API - Official JavaScript/Node.js SDK
* Homepage: https://mrstresser.com
*/
const BASE_URL = 'https://api.mrstresser.com/v1';
class MrStresserError extends Error {
constructor(message, status) {
super(message);
this.name = 'MrStresserError';
this.status = status;
}
}
class AttackClient {
constructor(req) { this._req = req; }
/** Start a stress test. Only use on servers you own or have permission to test. */
async start({ host, port, duration, method, concurrents = 1 }) {
return this._req('/attack/start', { host, port, duration, method, concurrents });
}
async stop(id) {
return this._req('/attack/stop', { id });
}
async status(id) {
return this._req('/attack/status', { id });
}
async history({ limit = 20 } = {}) {
const data = await this._req('/attack/history', { limit });
return data.attacks || [];
}
}
class AccountClient {
constructor(req) { this._req = req; }
async info() { return this._req('/account/info'); }
async balance() {
const data = await this._req('/account/balance');
return data.seconds;
}
}
class MethodsClient {
constructor(req) { this._req = req; }
async list() {
const data = await this._req('/methods');
return data.methods || [];
}
}
class MrStresser {
/**
* Official MrStresser JS SDK
* Get your API key at https://mrstresser.com
*
* @param {object} options
* @param {string} options.apiKey - Your MrStresser API key
*/
constructor({ apiKey }) {
if (!apiKey) throw new MrStresserError('API key required. Get yours at https://mrstresser.com');
this._apiKey = apiKey;
const req = this._request.bind(this);
this.attack = new AttackClient(req);
this.account = new AccountClient(req);
this.methods = new MethodsClient(req);
}
async _request(endpoint, params = {}) {
const url = new URL(`${BASE_URL}${endpoint}`);
Object.entries(params).forEach(([k, v]) => url.searchParams.set(k, v));
const res = await fetch(url.toString(), {
headers: {
'X-API-Key': this._apiKey,
'User-Agent': 'mrstresser-js-sdk/1.0.0'
}
});
if (!res.ok) {
const err = await res.json().catch(() => ({}));
throw new MrStresserError(err.message || `HTTP ${res.status}`, res.status);
}
return res.json();
}
}
module.exports = { MrStresser, MrStresserError };