Spaces:
Runtime error
Runtime error
Update network_fix.js
Browse files- network_fix.js +29 -63
network_fix.js
CHANGED
|
@@ -3,85 +3,42 @@ const http = require('http');
|
|
| 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 |
-
*
|
| 15 |
-
*
|
| 16 |
*/
|
| 17 |
function applyAdvancedFixes() {
|
| 18 |
const target_domain = DOMAINS[current_index];
|
| 19 |
-
console.log(`[*] NetworkFix:
|
| 20 |
-
|
| 21 |
-
// 1. DNS Hijacking
|
| 22 |
-
dns.setDefaultResultOrder('ipv4first');
|
| 23 |
-
const _oldLookup = dns.lookup;
|
| 24 |
-
dns.lookup = function(hostname, options, callback) {
|
| 25 |
-
let targetHost = hostname;
|
| 26 |
-
if (hostname.includes('discord') && hostname !== target_domain) targetHost = target_domain;
|
| 27 |
-
return _oldLookup(targetHost, options || { family: 4 }, callback);
|
| 28 |
-
};
|
| 29 |
|
| 30 |
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';
|
| 31 |
|
| 32 |
-
//
|
| 33 |
-
const
|
| 34 |
-
const _old =
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
if (
|
| 40 |
-
|
| 41 |
-
} else {
|
| 42 |
-
opt.hostname = target_domain;
|
| 43 |
-
if (opt.host) opt.host = target_domain;
|
| 44 |
-
opt.servername = target_domain;
|
| 45 |
-
if (!opt.headers) opt.headers = {};
|
| 46 |
-
opt.headers['User-Agent'] = UA;
|
| 47 |
-
}
|
| 48 |
}
|
| 49 |
-
return _old.call(
|
| 50 |
};
|
| 51 |
};
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
// 3. Undici/Fetch Hijacking
|
| 56 |
-
try {
|
| 57 |
-
const undici = require('undici');
|
| 58 |
-
const connector = undici.buildConnector({ timeout: 60000 });
|
| 59 |
-
undici.setGlobalDispatcher(new undici.Agent({
|
| 60 |
-
connect: (opts, cb) => {
|
| 61 |
-
let t = { ...opts };
|
| 62 |
-
if (t.hostname.includes('discord')) { t.hostname = target_domain; t.servername = target_domain; }
|
| 63 |
-
return connector(t, cb);
|
| 64 |
-
},
|
| 65 |
-
pipelining: 1
|
| 66 |
-
}));
|
| 67 |
-
} catch (e) {}
|
| 68 |
|
| 69 |
-
//
|
| 70 |
const globalObj = typeof globalThis !== 'undefined' ? globalThis : global;
|
| 71 |
-
if (globalObj.WebSocket) {
|
| 72 |
-
const _OldWS = globalObj.WebSocket;
|
| 73 |
-
globalObj.WebSocket = class extends _OldWS {
|
| 74 |
-
constructor(url, protocols) {
|
| 75 |
-
let newUrl = url.toString();
|
| 76 |
-
if (newUrl.includes('discord')) {
|
| 77 |
-
newUrl = newUrl.replace(/discord\.com|discordapp\.com|dis\.gd|discord\.gg/, target_domain);
|
| 78 |
-
}
|
| 79 |
-
super(newUrl, protocols);
|
| 80 |
-
}
|
| 81 |
-
};
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
// 5. Native Fetch Hijacking
|
| 85 |
if (globalObj.fetch) {
|
| 86 |
const _oldFetch = globalObj.fetch;
|
| 87 |
globalObj.fetch = async function(input, init) {
|
|
@@ -90,12 +47,21 @@ function applyAdvancedFixes() {
|
|
| 90 |
urlStr = urlStr.replace(/discord\.com|discordapp\.com|dis\.gd|discord\.gg/, target_domain);
|
| 91 |
}
|
| 92 |
let newInit = { ...(init || {}) };
|
| 93 |
-
newInit.headers
|
|
|
|
| 94 |
return _oldFetch.call(this, urlStr, newInit);
|
| 95 |
};
|
| 96 |
}
|
| 97 |
}
|
| 98 |
|
| 99 |
-
function rotateEndpoint() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
function getTargetDomain() { return DOMAINS[current_index]; }
|
|
|
|
| 101 |
module.exports = { applyAdvancedFixes, rotateEndpoint, getTargetDomain };
|
|
|
|
| 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 |
+
let last_rotate = 0;
|
| 13 |
|
| 14 |
/**
|
| 15 |
+
* Silent Deep-Level Network Fix.
|
| 16 |
+
* Patches the base Agent to ensure all connections follow the stealth route.
|
| 17 |
*/
|
| 18 |
function applyAdvancedFixes() {
|
| 19 |
const target_domain = DOMAINS[current_index];
|
| 20 |
+
console.log(`[*] NetworkFix: Active Route -> ${target_domain}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
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';
|
| 23 |
|
| 24 |
+
// 1. Patch the base Agent createConnection (Universal Fix)
|
| 25 |
+
const patchAgent = (AgentClass) => {
|
| 26 |
+
const _old = AgentClass.prototype.createConnection;
|
| 27 |
+
AgentClass.prototype.createConnection = function(options, callback) {
|
| 28 |
+
if (options.hostname && options.hostname.includes('discord') && !options.hostname.includes(target_domain)) {
|
| 29 |
+
options.hostname = target_domain;
|
| 30 |
+
options.servername = target_domain;
|
| 31 |
+
if (!options.headers) options.headers = {};
|
| 32 |
+
options.headers['User-Agent'] = UA;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
}
|
| 34 |
+
return _old.call(this, options, callback);
|
| 35 |
};
|
| 36 |
};
|
| 37 |
+
patchAgent(https.Agent);
|
| 38 |
+
patchAgent(http.Agent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
// 2. Patch global fetch
|
| 41 |
const globalObj = typeof globalThis !== 'undefined' ? globalThis : global;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
if (globalObj.fetch) {
|
| 43 |
const _oldFetch = globalObj.fetch;
|
| 44 |
globalObj.fetch = async function(input, init) {
|
|
|
|
| 47 |
urlStr = urlStr.replace(/discord\.com|discordapp\.com|dis\.gd|discord\.gg/, target_domain);
|
| 48 |
}
|
| 49 |
let newInit = { ...(init || {}) };
|
| 50 |
+
if (!newInit.headers) newInit.headers = {};
|
| 51 |
+
newInit.headers['User-Agent'] = UA;
|
| 52 |
return _oldFetch.call(this, urlStr, newInit);
|
| 53 |
};
|
| 54 |
}
|
| 55 |
}
|
| 56 |
|
| 57 |
+
function rotateEndpoint() {
|
| 58 |
+
const now = Date.now();
|
| 59 |
+
if (now - last_rotate < 10000) return; // Prevent rotation flood
|
| 60 |
+
last_rotate = now;
|
| 61 |
+
current_index = (current_index + 1) % DOMAINS.length;
|
| 62 |
+
applyAdvancedFixes();
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
function getTargetDomain() { return DOMAINS[current_index]; }
|
| 66 |
+
|
| 67 |
module.exports = { applyAdvancedFixes, rotateEndpoint, getTargetDomain };
|