Spaces:
Runtime error
Runtime error
Update ultimate_fix.js
Browse files- ultimate_fix.js +22 -68
ultimate_fix.js
CHANGED
|
@@ -1,70 +1,22 @@
|
|
| 1 |
-
const dns = require('dns');
|
| 2 |
const tls = require('tls');
|
| 3 |
const http = require('http');
|
| 4 |
const https = require('https');
|
| 5 |
|
| 6 |
-
|
| 7 |
-
* THE ULTIMATE FIX FOR HUGGING FACE SPACES
|
| 8 |
-
* This file forces the bot to bypass all network restrictions manually.
|
| 9 |
-
*/
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
if (dns.setDefaultResultOrder) {
|
| 15 |
-
dns.setDefaultResultOrder('ipv4first');
|
| 16 |
}
|
| 17 |
-
try {
|
| 18 |
-
// Use Cloudflare and Google as fallbacks
|
| 19 |
-
dns.setServers(['1.1.1.1', '8.8.8.8', '1.0.0.1']);
|
| 20 |
-
} catch(e) {}
|
| 21 |
-
|
| 22 |
-
// 2. Monkey-patch the global DNS system (The NUCLEAR FIX)
|
| 23 |
-
// We manually provide a diverse set of Discord's edge IPs to bypass Cloudflare IP blocks.
|
| 24 |
-
const DISCORD_IPS = [
|
| 25 |
-
'162.159.138.232', '162.159.137.232', '162.159.136.232', '162.159.135.232',
|
| 26 |
-
'162.159.129.232', '162.159.130.233', '162.159.133.232', '162.159.134.232',
|
| 27 |
-
'104.16.58.5', '104.16.59.5', '104.16.60.5', '104.16.61.5',
|
| 28 |
-
'172.67.147.230', '104.21.43.141', '104.18.25.27', '104.18.24.27'
|
| 29 |
-
];
|
| 30 |
-
let currentIpIndex = Math.floor(Math.random() * DISCORD_IPS.length);
|
| 31 |
-
|
| 32 |
-
const originalLookup = dns.lookup;
|
| 33 |
-
dns.lookup = function(hostname, options, callback) {
|
| 34 |
-
if (typeof options === 'function') {
|
| 35 |
-
callback = options;
|
| 36 |
-
options = { family: 4 };
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
const isDiscord = (hostname.includes('discord.com') ||
|
| 40 |
-
hostname.includes('discordapp.com') ||
|
| 41 |
-
hostname.includes('discord.gg')) &&
|
| 42 |
-
!hostname.includes('cdn.') &&
|
| 43 |
-
!hostname.includes('media.') &&
|
| 44 |
-
!hostname.includes('workers.dev');
|
| 45 |
-
|
| 46 |
-
if (isDiscord) {
|
| 47 |
-
const ip = DISCORD_IPS[currentIpIndex];
|
| 48 |
-
currentIpIndex = (currentIpIndex + 1) % DISCORD_IPS.length;
|
| 49 |
-
console.log(`[DNS] Direct Route: ${hostname} -> ${ip}`);
|
| 50 |
-
return callback(null, ip, 4);
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
if (options && !options.family) options.family = 4;
|
| 54 |
-
return originalLookup(hostname, options, callback);
|
| 55 |
-
};
|
| 56 |
|
| 57 |
-
//
|
| 58 |
tls.DEFAULT_MIN_VERSION = 'TLSv1.2';
|
| 59 |
tls.DEFAULT_MAX_VERSION = 'TLSv1.3';
|
| 60 |
-
// Force modern ciphers to avoid handshake failures
|
| 61 |
tls.DEFAULT_CIPHERS = 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384';
|
| 62 |
|
| 63 |
-
|
| 64 |
-
// 4. Force a fake Browser Identity globally
|
| 65 |
process.env.UNDICI_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36';
|
| 66 |
|
| 67 |
-
// 5. Build and set a Global Network Agent (With Transparent Proxy Support)
|
| 68 |
let dispatcher = null;
|
| 69 |
try {
|
| 70 |
const { setGlobalDispatcher, Agent, ProxyAgent } = require('undici');
|
|
@@ -74,7 +26,7 @@ try {
|
|
| 74 |
console.log(`>>> [ULTIMATE FIX] Proxy detected! Tunneling through: ${proxyUrl}`);
|
| 75 |
dispatcher = new ProxyAgent({
|
| 76 |
uri: proxyUrl.startsWith('http') ? proxyUrl : `http://${proxyUrl}`,
|
| 77 |
-
token: 'Basic ' + Buffer.from('user:pass').toString('base64'),
|
| 78 |
requestTimeout: 120000,
|
| 79 |
connect: {
|
| 80 |
timeout: 120000,
|
|
@@ -84,13 +36,14 @@ try {
|
|
| 84 |
} else {
|
| 85 |
dispatcher = new Agent({
|
| 86 |
connect: {
|
| 87 |
-
timeout:
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
keepAliveTimeout: 60000,
|
| 91 |
},
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
| 94 |
pipelining: 0,
|
| 95 |
maxRedirections: 5
|
| 96 |
});
|
|
@@ -98,17 +51,18 @@ try {
|
|
| 98 |
|
| 99 |
setGlobalDispatcher(dispatcher);
|
| 100 |
global.fixedDispatcher = dispatcher;
|
| 101 |
-
console.log(`>>> [ULTIMATE FIX] Global Dispatcher active (${proxyUrl ? 'PROXY MODE' : '
|
| 102 |
} catch (e) {
|
| 103 |
console.warn(">>> [ULTIMATE FIX] Undici setup error:", e.message);
|
| 104 |
}
|
| 105 |
|
| 106 |
-
//
|
| 107 |
-
http.globalAgent = new http.Agent({
|
| 108 |
-
https.globalAgent = new https.Agent({
|
| 109 |
|
| 110 |
-
console.log(">>> [ULTIMATE FIX] Network system
|
| 111 |
|
| 112 |
module.exports = {
|
| 113 |
-
dispatcher: dispatcher || global.fixedDispatcher || null
|
| 114 |
-
|
|
|
|
|
|
|
|
|
| 1 |
const tls = require('tls');
|
| 2 |
const http = require('http');
|
| 3 |
const https = require('https');
|
| 4 |
|
| 5 |
+
console.log(">>> [ULTIMATE FIX] Booting standard dual-stack network logic...");
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
// No-op since we are not hijacking DNS/IPs anymore
|
| 8 |
+
function rotateEndpoint() {
|
| 9 |
+
console.log(">>> [ULTIMATE FIX] rotateEndpoint called (DNS hijacking is disabled).");
|
|
|
|
|
|
|
| 10 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
// Keep standard TLS settings for compatibility, but don't reject unauthorized certs if needed
|
| 13 |
tls.DEFAULT_MIN_VERSION = 'TLSv1.2';
|
| 14 |
tls.DEFAULT_MAX_VERSION = 'TLSv1.3';
|
|
|
|
| 15 |
tls.DEFAULT_CIPHERS = 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384';
|
| 16 |
|
| 17 |
+
// Force a fake Browser Identity globally
|
|
|
|
| 18 |
process.env.UNDICI_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36';
|
| 19 |
|
|
|
|
| 20 |
let dispatcher = null;
|
| 21 |
try {
|
| 22 |
const { setGlobalDispatcher, Agent, ProxyAgent } = require('undici');
|
|
|
|
| 26 |
console.log(`>>> [ULTIMATE FIX] Proxy detected! Tunneling through: ${proxyUrl}`);
|
| 27 |
dispatcher = new ProxyAgent({
|
| 28 |
uri: proxyUrl.startsWith('http') ? proxyUrl : `http://${proxyUrl}`,
|
| 29 |
+
token: 'Basic ' + Buffer.from('user:pass').toString('base64'),
|
| 30 |
requestTimeout: 120000,
|
| 31 |
connect: {
|
| 32 |
timeout: 120000,
|
|
|
|
| 36 |
} else {
|
| 37 |
dispatcher = new Agent({
|
| 38 |
connect: {
|
| 39 |
+
timeout: 30000,
|
| 40 |
+
rejectUnauthorized: false
|
| 41 |
+
// family: 4 is removed to allow dual-stack lookup
|
|
|
|
| 42 |
},
|
| 43 |
+
keepAliveTimeout: 60000,
|
| 44 |
+
keepAliveMaxTimeout: 300000,
|
| 45 |
+
headersTimeout: 60000,
|
| 46 |
+
bodyTimeout: 60000,
|
| 47 |
pipelining: 0,
|
| 48 |
maxRedirections: 5
|
| 49 |
});
|
|
|
|
| 51 |
|
| 52 |
setGlobalDispatcher(dispatcher);
|
| 53 |
global.fixedDispatcher = dispatcher;
|
| 54 |
+
console.log(`>>> [ULTIMATE FIX] Global Dispatcher active (${proxyUrl ? 'PROXY MODE' : 'STANDARD MODE'}).`);
|
| 55 |
} catch (e) {
|
| 56 |
console.warn(">>> [ULTIMATE FIX] Undici setup error:", e.message);
|
| 57 |
}
|
| 58 |
|
| 59 |
+
// Fix legacy http/https modules (family: 4 removed)
|
| 60 |
+
http.globalAgent = new http.Agent({ keepAlive: true, keepAliveMsecs: 60000 });
|
| 61 |
+
https.globalAgent = new https.Agent({ keepAlive: true, keepAliveMsecs: 60000, rejectUnauthorized: false });
|
| 62 |
|
| 63 |
+
console.log(">>> [ULTIMATE FIX] Network system initialized with dual-stack (IPv4/IPv6) support.");
|
| 64 |
|
| 65 |
module.exports = {
|
| 66 |
+
dispatcher: dispatcher || global.fixedDispatcher || null,
|
| 67 |
+
rotateEndpoint
|
| 68 |
+
};
|