Spaces:
Runtime error
Runtime error
Update network_fix.js
Browse files- network_fix.js +33 -103
network_fix.js
CHANGED
|
@@ -3,129 +3,59 @@ const http = require('http');
|
|
| 3 |
const dns = require('dns');
|
| 4 |
|
| 5 |
const DOMAINS = [
|
| 6 |
-
"
|
| 7 |
-
"
|
| 8 |
-
"canary.discord.com",
|
| 9 |
-
"
|
| 10 |
];
|
| 11 |
let current_index = 0;
|
| 12 |
|
| 13 |
/**
|
| 14 |
-
*
|
| 15 |
-
*
|
| 16 |
*/
|
| 17 |
function applyAdvancedFixes() {
|
| 18 |
-
console.log("[*] NetworkFix:
|
| 19 |
|
| 20 |
-
dns.setDefaultResultOrder('ipv6first');
|
| 21 |
-
|
| 22 |
-
// Patch dns.lookup to be more flexible
|
| 23 |
-
const _oldLookup = dns.lookup;
|
| 24 |
-
dns.lookup = function(hostname, options, callback) {
|
| 25 |
-
let opt = options;
|
| 26 |
-
if (typeof opt === 'function') {
|
| 27 |
-
callback = opt;
|
| 28 |
-
opt = { family: 6 };
|
| 29 |
-
}
|
| 30 |
-
return _oldLookup(hostname, opt || { family: 6 }, callback);
|
| 31 |
-
};
|
| 32 |
-
|
| 33 |
// Connectivity Diagnostic
|
| 34 |
-
["google.com", "discord.com"
|
| 35 |
dns.resolve4(d, (err, addrs) => {
|
| 36 |
console.log(`[*] DNS Test: ${d} -> ${err ? 'FAILED (' + err.code + ')' : addrs[0]}`);
|
| 37 |
});
|
| 38 |
});
|
| 39 |
|
| 40 |
const target_domain = DOMAINS[current_index];
|
| 41 |
-
console.log(`[*] NetworkFix: Forcing traffic through ${target_domain}...`);
|
| 42 |
-
|
| 43 |
-
// Basic Connectivity Test
|
| 44 |
-
global.fetch && global.fetch("https://www.google.com").then(r => console.log(`[*] Network Test: google.com -> ${r.status}`)).catch(e => console.log(`[!] Network Test: google.com -> FAILED (${e.message})`));
|
| 45 |
|
| 46 |
-
// REST API Test
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
if (typeof opt === 'string') {
|
| 57 |
-
if (isDiscord(opt) && !isAsset(opt)) opt = opt.replace(/discord\.com|discordapp\.com|dis\.gd|discord\.gg/, target_domain);
|
| 58 |
-
} else {
|
| 59 |
-
const host = opt.hostname || opt.host;
|
| 60 |
-
if (isDiscord(host) && !isAsset(host)) {
|
| 61 |
-
opt.hostname = target_domain;
|
| 62 |
-
if (opt.host) opt.host = target_domain;
|
| 63 |
-
opt.servername = target_domain;
|
| 64 |
-
}
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
if (typeof opt !== 'string') {
|
| 68 |
-
if (!opt.agent && !opt.createConnection) opt.agent = https.globalAgent;
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
return _oldRequest.call(https, opt, callback);
|
| 72 |
-
};
|
| 73 |
-
|
| 74 |
-
const options = { keepAlive: true, timeout: 60000 };
|
| 75 |
-
https.globalAgent = new https.Agent(options);
|
| 76 |
-
http.globalAgent = new http.Agent(options);
|
| 77 |
-
|
| 78 |
-
try {
|
| 79 |
-
const undici = require('undici');
|
| 80 |
-
const dispatcher = new undici.Agent({
|
| 81 |
-
connect: {
|
| 82 |
-
timeout: 60000
|
| 83 |
-
},
|
| 84 |
-
pipelining: 1,
|
| 85 |
-
keepAliveTimeout: 90000,
|
| 86 |
-
bodyTimeout: 90000,
|
| 87 |
-
headersTimeout: 90000
|
| 88 |
-
});
|
| 89 |
-
undici.setGlobalDispatcher(dispatcher);
|
| 90 |
-
} catch (e) {
|
| 91 |
-
console.log("[!] NetworkFix: undici dispatcher not set:", e.message);
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
// Patch global fetch if it exists (Node 18+)
|
| 95 |
-
const globalObj = typeof globalThis !== 'undefined' ? globalThis : global;
|
| 96 |
-
if (globalObj.fetch) {
|
| 97 |
-
const _oldFetch = globalObj.fetch;
|
| 98 |
-
globalObj.fetch = async function(input, init) {
|
| 99 |
-
let urlStr = typeof input === 'string' ? input : (input.url || input.toString());
|
| 100 |
-
let newInit = { ...init };
|
| 101 |
-
if (!newInit.headers) newInit.headers = {};
|
| 102 |
-
|
| 103 |
-
// Spoof User-Agent
|
| 104 |
-
const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
|
| 105 |
-
if (newInit.headers instanceof Headers) {
|
| 106 |
-
newInit.headers.set('User-Agent', UA);
|
| 107 |
-
} else if (Array.isArray(newInit.headers)) {
|
| 108 |
-
newInit.headers.push(['User-Agent', UA]);
|
| 109 |
-
} else {
|
| 110 |
-
newInit.headers['User-Agent'] = UA;
|
| 111 |
-
}
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
}
|
| 121 |
-
return _oldFetch.call(this, url.toString(), newInit);
|
| 122 |
-
} catch (e) {
|
| 123 |
-
return _oldFetch.call(this, input, newInit);
|
| 124 |
}
|
|
|
|
| 125 |
};
|
| 126 |
}
|
| 127 |
-
|
| 128 |
-
console.log("[*] NetworkFix: Hijacker Active.");
|
| 129 |
}
|
| 130 |
|
| 131 |
function rotateEndpoint() {
|
|
|
|
| 3 |
const dns = require('dns');
|
| 4 |
|
| 5 |
const DOMAINS = [
|
| 6 |
+
"discord.com",
|
| 7 |
+
"ptb.discord.com",
|
| 8 |
+
"canary.discord.com",
|
| 9 |
+
"discordapp.com"
|
| 10 |
];
|
| 11 |
let current_index = 0;
|
| 12 |
|
| 13 |
/**
|
| 14 |
+
* Minimal Network Fix.
|
| 15 |
+
* Attempts direct connection first, then rotates.
|
| 16 |
*/
|
| 17 |
function applyAdvancedFixes() {
|
| 18 |
+
console.log("[*] NetworkFix: Running in Minimal Recovery Mode...");
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
// Connectivity Diagnostic
|
| 21 |
+
["google.com", "discord.com"].forEach(d => {
|
| 22 |
dns.resolve4(d, (err, addrs) => {
|
| 23 |
console.log(`[*] DNS Test: ${d} -> ${err ? 'FAILED (' + err.code + ')' : addrs[0]}`);
|
| 24 |
});
|
| 25 |
});
|
| 26 |
|
| 27 |
const target_domain = DOMAINS[current_index];
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
// REST API Test using standard https module for more detail
|
| 30 |
+
const req = https.get(`https://${target_domain}/api/v10/gateway`, (res) => {
|
| 31 |
+
console.log(`[*] REST Test: ${target_domain} -> ${res.statusCode}`);
|
| 32 |
+
});
|
| 33 |
+
|
| 34 |
+
req.on('error', (e) => {
|
| 35 |
+
console.log(`[!] REST Test: ${target_domain} -> FAILED (${e.code || e.message})`);
|
| 36 |
+
});
|
| 37 |
+
|
| 38 |
+
req.end();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
// Hijacker - Only active if we have a rotated domain
|
| 41 |
+
if (current_index > 0) {
|
| 42 |
+
console.log(`[*] NetworkFix: Hijacker Active -> ${target_domain}`);
|
| 43 |
+
const _oldRequest = https.request;
|
| 44 |
+
https.request = function(options, callback) {
|
| 45 |
+
let opt = options;
|
| 46 |
+
const host = typeof opt === 'string' ? opt : (opt.hostname || opt.host);
|
| 47 |
+
if (host && host.includes('discord.com')) {
|
| 48 |
+
if (typeof opt === 'string') {
|
| 49 |
+
opt = opt.replace('discord.com', target_domain);
|
| 50 |
+
} else {
|
| 51 |
+
opt.hostname = target_domain;
|
| 52 |
+
if (opt.host) opt.host = target_domain;
|
| 53 |
+
opt.servername = target_domain;
|
| 54 |
}
|
|
|
|
|
|
|
|
|
|
| 55 |
}
|
| 56 |
+
return _oldRequest.call(https, opt, callback);
|
| 57 |
};
|
| 58 |
}
|
|
|
|
|
|
|
| 59 |
}
|
| 60 |
|
| 61 |
function rotateEndpoint() {
|