Last active
March 31, 2025 08:53
-
-
Save AliMilani/b73bc543b8a7cc5833afcd927f7310e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const http = require("http"); | |
| const path = require("path"); | |
| const { execSync, spawn } = require("child_process"); | |
| const PORT = 8765; | |
| const PROXY_PORT = 10808; | |
| // Function to get the Default Gateway (Android IP) | |
| function getAndroidIP() { | |
| try { | |
| // Run ipconfig command and get output as a string | |
| const output = execSync("ipconfig", { encoding: "utf-8" }); | |
| // Match the "Default Gateway" line (IPv4 format) | |
| const match = output.match(/Default Gateway .+\s+(\d+\.\d+\.\d+\.\d+)/); | |
| if (match) { | |
| return match[1]; // Extracted IP address | |
| } else { | |
| console.log("Android IP (Default Gateway) not found."); | |
| return null; | |
| } | |
| } catch (err) { | |
| console.error("Error getting Android IP:", err); | |
| return null; | |
| } | |
| } | |
| const ANDROID_PROXY_IP = getAndroidIP() || "192.168.0.1"; // Fallback IP | |
| console.log("Detected Android Proxy IP:", ANDROID_PROXY_IP); | |
| const ANDROID_PROXY_PORT = 10808; // Android Proxy Port | |
| // Function to start a GOST proxy with specific configuration | |
| function startGostProxy(localPort, localType, remoteType) { | |
| const gostPath = path.join(__dirname, "gost.exe"); | |
| const localEndpoint = localType ? `${localType}://127.0.0.1:${localPort}` : `:${localPort}`; | |
| const remoteEndpoint = `${remoteType}://${ANDROID_PROXY_IP}:${ANDROID_PROXY_PORT}`; | |
| console.log(`Starting proxy: ${localEndpoint} -> ${remoteEndpoint}`); | |
| const gostProcess = spawn(gostPath, [ | |
| `-L=${localEndpoint}`, | |
| `-F=${remoteEndpoint}` | |
| ]); | |
| gostProcess.stdout.on('data', (data) => { | |
| console.log(`[GOST ${localPort}] ${data}`); | |
| }); | |
| gostProcess.stderr.on('data', (data) => { | |
| console.error(`[GOST ${localPort} ERROR] ${data}`); | |
| }); | |
| return gostProcess; | |
| } | |
| // Create an HTTP server to serve the PAC file | |
| const server = http.createServer((req, res) => { | |
| if (req.url === "/proxy.pac") { | |
| const pacContent = ` | |
| function FindProxyForURL(url, host) { | |
| return "PROXY ${ANDROID_PROXY_IP}:${PROXY_PORT}; DIRECT"; | |
| } | |
| `; | |
| res.writeHead(200, { "Content-Type": "application/x-ns-proxy-autoconfig" }); | |
| res.end(pacContent); | |
| } else { | |
| res.writeHead(404, { "Content-Type": "text/plain" }); | |
| res.end("Not Found"); | |
| } | |
| }); | |
| // Start the HTTP server | |
| server.listen(PORT, () => { | |
| console.log(`PAC file server running at http://localhost:${PORT}/proxy.pac`); | |
| // Start proxy configurations | |
| const proxyConfigs = [ | |
| { port: 9876, localType: null, remoteType: 'socks5' }, // Default on port 9876 | |
| { port: 1080, localType: 'socks5', remoteType: 'socks5' }, // SOCKS5 proxy on port 1080 | |
| { port: 8080, localType: 'http', remoteType: 'socks5' } // HTTP proxy on port 8080 | |
| ]; | |
| // Start all proxy configurations | |
| const runningProxies = proxyConfigs.map(config => | |
| startGostProxy(config.port, config.localType, config.remoteType) | |
| ); | |
| console.log(`Started ${runningProxies.length} proxy endpoints`); | |
| // Handle process termination | |
| process.on('SIGINT', () => { | |
| console.log('Shutting down all proxies...'); | |
| runningProxies.forEach(process => process.kill()); | |
| process.exit(0); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
taskschd.msc