Download check_proxy_alive.js from vipsphi/luadao: direct link, hf CLI and curl.
- Browser
- Download file 2.35 kB
-
https://huggingface.co/spaces/vipsphi/luadao/resolve/main/check_proxy_alive.js
- Command line
-
hf download hf://spaces/vipsphi/luadao/check_proxy_alive.js
-
curl -L -o check_proxy_alive.js https://huggingface.co/spaces/vipsphi/luadao/resolve/main/check_proxy_alive.js
2.35 kB
| const http = require('http'); | |
| const https = require('https'); | |
| async function testProxy(protocol, targetHost, targetPath) { | |
| const proxy = 'http://zlet9i3y:oZJQ0o4V@157.10.49.215:44128'; | |
| const targetUrl = `${protocol}://${targetHost}${targetPath}`; | |
| console.log(`Testing Proxy: ${proxy}`); | |
| console.log(`Target: ${targetUrl}`); | |
| const url = new URL(proxy); | |
| const auth = 'Basic ' + Buffer.from(url.username + ':' + url.password).toString('base64'); | |
| if (protocol === 'http') { | |
| return new Promise((resolve) => { | |
| const options = { | |
| host: url.hostname, | |
| port: url.port, | |
| path: targetUrl, | |
| headers: { | |
| 'Proxy-Authorization': auth, | |
| 'Host': targetHost | |
| } | |
| }; | |
| http.get(options, (res) => { | |
| let data = ''; | |
| res.on('data', chunk => data += chunk); | |
| res.on('end', () => { | |
| console.log(`HTTP Status: ${res.statusCode}`); | |
| resolve(true); | |
| }); | |
| }).on('error', e => { | |
| console.error(`HTTP Proxy Error: ${e.message}`); | |
| resolve(false); | |
| }); | |
| }); | |
| } else { | |
| // HTTPS CONNECT | |
| return new Promise((resolve) => { | |
| const req = http.request({ | |
| host: url.hostname, | |
| port: url.port, | |
| method: 'CONNECT', | |
| path: `${targetHost}:443`, | |
| headers: { | |
| 'Proxy-Authorization': auth | |
| } | |
| }); | |
| req.on('connect', (res, socket, head) => { | |
| console.log('HTTPS CONNECT established'); | |
| socket.destroy(); | |
| resolve(true); | |
| }); | |
| req.on('error', e => { | |
| console.error(`HTTPS Proxy Error (CONNECT): ${e.message}`); | |
| resolve(false); | |
| }); | |
| req.end(); | |
| }); | |
| } | |
| } | |
| async function run() { | |
| console.log('--- Step 1: HTTP Test ---'); | |
| await testProxy('http', 'httpbin.org', '/ip'); | |
| console.log('\n--- Step 2: HTTPS Test ---'); | |
| await testProxy('https', 'labs.google', '/'); | |
| } | |
| run(); | |