I'm struggling to find the correct terminology to accurately phrase this problem, but I'm gonna give it my best shot:
In node.js, is there a way to manually override the IP address when making an HTTP request (e.g. request some-domain.com/whatever
and instead of resolving the IP address through DNS, manually provide some IP address 1.2.3.4
) ?
This would, effectively speaking, be the equivalent of setting 1.2.3.4 some-domain.com
in /etc/hosts
There is a tiny module that does exactly that: evil-dns.
evilDns.add('foo.com', '1.2.3.4');
Node's http and https modules take an Agent as an argument, and you can override the dns resolver with the lookup
parameter.
const http = require("http");
const https = require("https");
const staticLookup = (ip, v) => (hostname, opts, cb) => cb(null, ip, v || 4)
const staticDnsAgent = (scheme, ip) => new require(scheme).Agent({lookup: staticLookup(ip)})
http.get("http://some-domain.com/whatever", {agent: staticDnsAgent('http', '1.2.3.4')})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With