How can I implement a SOCKS proxy to make requests to the whois protocol?

48 views Asked by At

Having trouble wrapping my head around making requests through the SOCKS proxy to whois.lookup.

I have a socks proxy (smartproxy) and a node server. I've tried tunnel, request, socks-proxy-agent, It seems I'm missing the mark completely.

Example of what I'm trying to accomplish:

const whois = require('whois');
const { SocksProxyAgent } = require('socks-proxy-agent');

const domain = 'google.com';

const proxyAgent = new SocksProxyAgent(`socks5://myproxy`);

whois.lookup(domain, { proxy: proxyAgent }, (err, data) => {
    if (err) {
        console.error(err.message);
    } else {
        console.log('WHOIS Data:', data);
    }
});
1

There are 1 answers

0
bogdanoff On

From README page, whois package has builtin option for communicating with socks proxies. You just need to config it and no need to use socks-proxy-agent.

const whois = require('whois');
const domain = 'google.com';

whois.lookup(domain, { proxy: { host: "myproxy", port: 8080 , type: 5 }  }, (err, data) => {
    if (err) {
        console.error(err.message);
    } else {
        console.log('WHOIS Data:', data);
    }
});