Spaces:
Runtime error
Runtime error
Update network_fix.js
Browse files- network_fix.js +18 -47
network_fix.js
CHANGED
|
@@ -3,84 +3,55 @@ const http = require('http');
|
|
| 3 |
const dns = require('dns');
|
| 4 |
|
| 5 |
const DOMAINS = [
|
| 6 |
-
"ptb.discord.com",
|
| 7 |
"discordapp.com",
|
|
|
|
| 8 |
"canary.discord.com",
|
| 9 |
"discord.com"
|
| 10 |
];
|
| 11 |
let current_index = 0;
|
| 12 |
|
| 13 |
/**
|
| 14 |
-
*
|
| 15 |
-
*
|
| 16 |
*/
|
| 17 |
function applyAdvancedFixes() {
|
| 18 |
const target_domain = DOMAINS[current_index];
|
| 19 |
-
console.log(`[*] NetworkFix:
|
| 20 |
|
| 21 |
const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36';
|
| 22 |
-
const STEALTH_HEADERS = {
|
| 23 |
-
'User-Agent': UA,
|
| 24 |
-
'Accept': '*/*',
|
| 25 |
-
'Accept-Language': 'en-US,en;q=0.9',
|
| 26 |
-
'Cache-Control': 'no-cache',
|
| 27 |
-
'Pragma': 'no-cache',
|
| 28 |
-
'Sec-Ch-Ua': '"Not A(Brand";v="99", "Google Chrome";v="121", "Chromium";v="121"',
|
| 29 |
-
'Sec-Ch-Ua-Mobile': '?0',
|
| 30 |
-
'Sec-Ch-Ua-Platform': '"Windows"',
|
| 31 |
-
'Sec-Fetch-Dest': 'empty',
|
| 32 |
-
'Sec-Fetch-Mode': 'cors',
|
| 33 |
-
'Sec-Fetch-Site': 'same-origin'
|
| 34 |
-
};
|
| 35 |
|
| 36 |
// 1. Patch https.request
|
| 37 |
const _oldRequest = https.request;
|
| 38 |
https.request = function(options, callback) {
|
| 39 |
let opt = options;
|
| 40 |
const host = typeof opt === 'string' ? opt : (opt.hostname || opt.host);
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
if (isDiscord(host)) {
|
| 44 |
if (typeof opt === 'string') {
|
| 45 |
opt = opt.replace(/discord\.com|discordapp\.com|dis\.gd|discord\.gg/, target_domain);
|
| 46 |
} else {
|
| 47 |
opt.hostname = target_domain;
|
| 48 |
if (opt.host) opt.host = target_domain;
|
| 49 |
-
opt.servername = target_domain;
|
| 50 |
if (!opt.headers) opt.headers = {};
|
| 51 |
-
|
| 52 |
}
|
| 53 |
}
|
| 54 |
return _oldRequest.call(https, opt, callback);
|
| 55 |
};
|
| 56 |
|
| 57 |
-
// 2. Patch
|
| 58 |
-
try {
|
| 59 |
-
const undici = require('undici');
|
| 60 |
-
const connector = undici.buildConnector({ timeout: 60000 });
|
| 61 |
-
const dispatcher = new undici.Agent({
|
| 62 |
-
connect: (opts, cb) => {
|
| 63 |
-
let targetOpts = { ...opts };
|
| 64 |
-
if (opts.hostname.includes('discord')) {
|
| 65 |
-
targetOpts.hostname = target_domain;
|
| 66 |
-
targetOpts.servername = target_domain;
|
| 67 |
-
}
|
| 68 |
-
return connector(targetOpts, cb);
|
| 69 |
-
},
|
| 70 |
-
pipelining: 1,
|
| 71 |
-
keepAliveTimeout: 90000
|
| 72 |
-
});
|
| 73 |
-
undici.setGlobalDispatcher(dispatcher);
|
| 74 |
-
} catch (e) {}
|
| 75 |
-
|
| 76 |
-
// 3. Patch global fetch
|
| 77 |
const globalObj = typeof globalThis !== 'undefined' ? globalThis : global;
|
| 78 |
if (globalObj.fetch) {
|
| 79 |
const _oldFetch = globalObj.fetch;
|
| 80 |
globalObj.fetch = async function(input, init) {
|
| 81 |
let urlStr = typeof input === 'string' ? input : (input.url || input.toString());
|
| 82 |
let newInit = { ...init };
|
| 83 |
-
newInit.headers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
try {
|
| 86 |
const url = new URL(urlStr);
|
|
@@ -94,10 +65,10 @@ function applyAdvancedFixes() {
|
|
| 94 |
};
|
| 95 |
}
|
| 96 |
|
| 97 |
-
//
|
| 98 |
-
|
| 99 |
-
.
|
| 100 |
-
|
| 101 |
}
|
| 102 |
|
| 103 |
function rotateEndpoint() {
|
|
|
|
| 3 |
const dns = require('dns');
|
| 4 |
|
| 5 |
const DOMAINS = [
|
|
|
|
| 6 |
"discordapp.com",
|
| 7 |
+
"ptb.discord.com",
|
| 8 |
"canary.discord.com",
|
| 9 |
"discord.com"
|
| 10 |
];
|
| 11 |
let current_index = 0;
|
| 12 |
|
| 13 |
/**
|
| 14 |
+
* Balanced Network Fix.
|
| 15 |
+
* Uses discordapp.com as primary route with browser headers.
|
| 16 |
*/
|
| 17 |
function applyAdvancedFixes() {
|
| 18 |
const target_domain = DOMAINS[current_index];
|
| 19 |
+
console.log(`[*] NetworkFix: Route -> ${target_domain}`);
|
| 20 |
|
| 21 |
const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
// 1. Patch https.request
|
| 24 |
const _oldRequest = https.request;
|
| 25 |
https.request = function(options, callback) {
|
| 26 |
let opt = options;
|
| 27 |
const host = typeof opt === 'string' ? opt : (opt.hostname || opt.host);
|
| 28 |
+
if (host && host.includes('discord')) {
|
|
|
|
|
|
|
| 29 |
if (typeof opt === 'string') {
|
| 30 |
opt = opt.replace(/discord\.com|discordapp\.com|dis\.gd|discord\.gg/, target_domain);
|
| 31 |
} else {
|
| 32 |
opt.hostname = target_domain;
|
| 33 |
if (opt.host) opt.host = target_domain;
|
|
|
|
| 34 |
if (!opt.headers) opt.headers = {};
|
| 35 |
+
opt.headers['User-Agent'] = UA;
|
| 36 |
}
|
| 37 |
}
|
| 38 |
return _oldRequest.call(https, opt, callback);
|
| 39 |
};
|
| 40 |
|
| 41 |
+
// 2. Patch global fetch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
const globalObj = typeof globalThis !== 'undefined' ? globalThis : global;
|
| 43 |
if (globalObj.fetch) {
|
| 44 |
const _oldFetch = globalObj.fetch;
|
| 45 |
globalObj.fetch = async function(input, init) {
|
| 46 |
let urlStr = typeof input === 'string' ? input : (input.url || input.toString());
|
| 47 |
let newInit = { ...init };
|
| 48 |
+
if (!newInit.headers) newInit.headers = {};
|
| 49 |
+
|
| 50 |
+
if (newInit.headers instanceof Headers) {
|
| 51 |
+
newInit.headers.set('User-Agent', UA);
|
| 52 |
+
} else {
|
| 53 |
+
newInit.headers['User-Agent'] = UA;
|
| 54 |
+
}
|
| 55 |
|
| 56 |
try {
|
| 57 |
const url = new URL(urlStr);
|
|
|
|
| 65 |
};
|
| 66 |
}
|
| 67 |
|
| 68 |
+
// Connectivity Tests
|
| 69 |
+
["google.com", "1.1.1.1"].forEach(d => {
|
| 70 |
+
dns.resolve4(d, (err, addrs) => console.log(`[*] DNS Check: ${d} -> ${err ? 'FAIL' : addrs[0]}`));
|
| 71 |
+
});
|
| 72 |
}
|
| 73 |
|
| 74 |
function rotateEndpoint() {
|