Brozy123 commited on
Commit
c57056b
·
verified ·
1 Parent(s): 14a23bc

Update network_fix.js

Browse files
Files changed (1) hide show
  1. network_fix.js +54 -72
network_fix.js CHANGED
@@ -11,109 +11,91 @@ const DOMAINS = [
11
  let current_index = 0;
12
 
13
  /**
14
- * High-Stability Network Fix.
15
- * Forces IPv4 and increases timeouts for slow cloud environments.
16
  */
17
  function applyAdvancedFixes() {
18
  const target_domain = DOMAINS[current_index];
19
- console.log(`[*] NetworkFix: Active Route -> ${target_domain}`);
20
 
21
- // 1. DNS Level Hijacking (The "Inner Ear" Fix)
22
  dns.setDefaultResultOrder('ipv4first');
23
  const _oldLookup = dns.lookup;
24
  dns.lookup = function(hostname, options, callback) {
25
  let targetHost = hostname;
26
- const isDiscord = (h) => h && (h.includes('discord.com') || h.includes('discordapp.com') || h.includes('dis.gd') || h.includes('discord.gg') || h.includes('discordapp.net'));
27
-
28
- // If the bot asks for any Discord domain, give it the rotated domain's IP
29
- if (isDiscord(hostname) && hostname !== target_domain) {
30
- targetHost = target_domain;
31
- }
32
-
33
- let opt = options || {};
34
- if (typeof opt === 'function') { callback = opt; opt = { family: 4 }; }
35
- else if (typeof opt === 'object') opt.family = 4;
36
-
37
- return _oldLookup(targetHost, opt, callback);
38
  };
39
 
40
  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';
41
 
42
- // 2. Patch https.request
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')) {
48
- if (typeof opt === 'string') {
49
- opt = opt.replace(/discord\.com|discordapp\.com|dis\.gd|discord\.gg/, target_domain);
50
- } else {
51
- opt.hostname = target_domain;
52
- if (opt.host) opt.host = target_domain;
53
- opt.servername = target_domain;
54
- if (!opt.headers) opt.headers = {};
55
- opt.headers['User-Agent'] = UA;
56
- opt.family = 4;
57
- opt.timeout = 60000;
58
  }
59
- }
60
- return _oldRequest.call(https, opt, callback);
61
  };
 
 
62
 
63
- // 3. Patch undici
64
  try {
65
  const undici = require('undici');
66
  const connector = undici.buildConnector({ timeout: 60000 });
67
- const dispatcher = new undici.Agent({
68
  connect: (opts, cb) => {
69
- let targetOpts = { ...opts };
70
- if (opts.hostname.includes('discord')) {
71
- targetOpts.hostname = target_domain;
72
- targetOpts.servername = target_domain;
73
- }
74
- return connector(targetOpts, cb);
75
  },
76
- pipelining: 1,
77
- keepAliveTimeout: 90000,
78
- bodyTimeout: 90000,
79
- headersTimeout: 90000
80
- });
81
- undici.setGlobalDispatcher(dispatcher);
82
  } catch (e) {}
83
 
84
- // 4. Patch global fetch
85
  const globalObj = typeof globalThis !== 'undefined' ? globalThis : global;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  if (globalObj.fetch) {
87
  const _oldFetch = globalObj.fetch;
88
  globalObj.fetch = async function(input, init) {
89
  let urlStr = typeof input === 'string' ? input : (input.url || input.toString());
90
- let newInit = { ...init };
91
- if (!newInit.headers) newInit.headers = {};
92
-
93
- if (newInit.headers instanceof Headers) {
94
- newInit.headers.set('User-Agent', UA);
95
- } else {
96
- newInit.headers['User-Agent'] = UA;
97
- }
98
-
99
- try {
100
- const url = new URL(urlStr);
101
- if (url.hostname.includes('discord')) {
102
- url.hostname = target_domain;
103
- }
104
- return _oldFetch.call(this, url.toString(), newInit);
105
- } catch (e) {
106
- return _oldFetch.call(this, input, newInit);
107
  }
 
 
 
108
  };
109
  }
110
  }
111
 
112
- function rotateEndpoint() {
113
- current_index = (current_index + 1) % DOMAINS.length;
114
- applyAdvancedFixes();
115
- }
116
-
117
  function getTargetDomain() { return DOMAINS[current_index]; }
118
-
119
  module.exports = { applyAdvancedFixes, rotateEndpoint, getTargetDomain };
 
11
  let current_index = 0;
12
 
13
  /**
14
+ * Ultimate Network Fix (God-Mode).
15
+ * Intercepts all low-level connections including WebSockets and Native Fetch.
16
  */
17
  function applyAdvancedFixes() {
18
  const target_domain = DOMAINS[current_index];
19
+ console.log(`[*] NetworkFix: Forcing Path -> ${target_domain}`);
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
+ // 2. HTTPS/HTTP Hijacking (WebSocket Handshake)
33
+ const patchRequest = (mod) => {
34
+ const _old = mod.request;
35
+ mod.request = function(options, callback) {
36
+ let opt = options;
37
+ const host = typeof opt === 'string' ? opt : (opt.hostname || opt.host);
38
+ if (host && host.includes('discord') && !host.includes(target_domain)) {
39
+ if (typeof opt === 'string') {
40
+ opt = opt.replace(/discord\.com|discordapp\.com|dis\.gd|discord\.gg/, target_domain);
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(mod, opt, callback);
50
+ };
51
  };
52
+ patchRequest(https);
53
+ patchRequest(http);
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
+ // 4. Native WebSocket Hijacking (Node 20+)
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) {
88
  let urlStr = typeof input === 'string' ? input : (input.url || input.toString());
89
+ if (urlStr.includes('discord')) {
90
+ urlStr = urlStr.replace(/discord\.com|discordapp\.com|dis\.gd|discord\.gg/, target_domain);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  }
92
+ let newInit = { ...(init || {}) };
93
+ newInit.headers = { ...(newInit.headers || {}), 'User-Agent': UA };
94
+ return _oldFetch.call(this, urlStr, newInit);
95
  };
96
  }
97
  }
98
 
99
+ function rotateEndpoint() { current_index = (current_index + 1) % DOMAINS.length; applyAdvancedFixes(); }
 
 
 
 
100
  function getTargetDomain() { return DOMAINS[current_index]; }
 
101
  module.exports = { applyAdvancedFixes, rotateEndpoint, getTargetDomain };