6

is any way, how i can get TXT record from specific domain name via JavaScript in browser ?

Because we use anycast network, we need info, what node is requested from user location and show on the website. Because nodes has no websever, any relevant information is in TXT record of specific domain name.

Gransy
  • 111
  • 1
  • 3
  • 1
    I don't think there's any way to do a DNS lookup directly from the browser. Write a server script to do it, and call it with AJAX. – Barmar Aug 23 '18 at 16:25
  • Looks like Google has a public DNS API: https://developers.google.com/speed/public-dns/docs/dns-over-https – Barmar Aug 23 '18 at 16:26
  • @Barmar server-side script or any API is not possible use, because it will return responses in servers. It can be completelly different than client responses, because server have another anycast node near. – Gransy Aug 23 '18 at 16:30
  • Firefox 60 or up has `resolve`: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/dns/resolve but you do not seem to be able to choose the type. So you could in some way implement your idea (if I understood correctly), just do not use TXT but create a specific `somesignal.example.com` `A` or `AAAA` record that will give a specific IP address, which has no real meaning except for your application. This could give you ideas too: https://security.stackexchange.com/questions/129917/how-does-a-website-know-the-dns-server-a-client-uses That is a standard trick. – Patrick Mevzek Aug 23 '18 at 17:48
  • check https://stackoverflow.com/questions/102605/can-i-perform-a-dns-lookup-hostname-to-ip-address-using-client-side-javascript – Amir Fo Aug 23 '18 at 17:51

1 Answers1

3

Lots of stuff isn't possible with JavaScript in the average browser. I'm 97% certain that this is one of them. What you could do is write a small script on your server that does this lookup, or use ActiveX, Flash or Java to run nslookup on the client machine.

You could also use Cloudflare's DNS over HTTPS for this purpose. (Other DNS over HTTPS providers exist.) It's the same as the server technique, except somebody else has already done it. See this webpage for full details, but here's an example request URL:

https://cloudflare-dns.com/dns-query?name=example.com&type=TXT

Other DNS over HTTPS providers are available; for instance, here is the list of providers available in Firefox. I strongly recommend running your own server, instead of using one of these providers, if at all possible – it's significantly better for your users' privacy.

wizzwizz4
  • 6,140
  • 2
  • 26
  • 62
  • This solution will return records what was resolved on server (or any API provider) but not on client ISP :( – Gransy Aug 23 '18 at 16:34
  • You can't do it directly from JavaScript, but the first paragraph is a pointer to ways of doing it client-side (namely, a scripting add-on) – wizzwizz4 Aug 23 '18 at 16:35
  • It has nothing to do with JavaScript... it has to do with the APIs the browser has (or hasn't) made available. – Brad Aug 23 '18 at 16:38
  • @Brad I know; it's an annoying colloquialism that I've picked up. I mean "standards-compliant browser JavaScript". You'll note that I mentioned that ActiveX could do it, and ActiveX is accessible from IE JavaScript. – wizzwizz4 Aug 23 '18 at 16:40
  • More importantly... JavaScript server-side or even JavaScript in-browser in a browser extension can do it. I just like to point this out because a lot of people get confused, thinking that "JavaScript can't do X", when it has nothing to do with the language itself. – Brad Aug 23 '18 at 16:43
  • 1
    1) "run nslookup on the client machine" this creates all sort of problems and `dig` should be prefered over `nslookup` anyway 2) many providers do DNS over HTTPS now, not only CloudFlare. This is soon to become a standard specification. – Patrick Mevzek Aug 23 '18 at 17:41
  • @PatrickMevzek Cloudfare's recommended by Mozilla. I'm wary of recommending Google for this job because Google already owns so much infrastructure and I have a healthy sense of paranoia. – wizzwizz4 Aug 23 '18 at 17:43
  • 1
    I wouldn't recommend either (and Mozilla endorsement certainly does not count, on the contrary the mandatory use of this option in their newer Firefox versions is just a signal in wrong direction). Or, more precisely, I would prefer to have people understand that there is choice, they should not rush to any one, they should first understand that each one comes with its own compromises. – Patrick Mevzek Aug 23 '18 at 17:44
  • "Google already owns so much infrastructure" yeah like CloudFlare did not own a whole chunk of the web space :-) .... – Patrick Mevzek Aug 23 '18 at 17:45
  • @PatrickMevzek But Google hasn't promised to play nice, whereas Cloudflare's promised not to exploit its DNS users. ... I'm acting like they're the only options, aren't I? :-/ – wizzwizz4 Aug 23 '18 at 17:48
  • 2
    If you're looking for more optoins, Curl's DNS over HTTPS wiki page has long, a frequently-updated list of public DoH providers (https://github.com/curl/curl/wiki/DNS-over-HTTPS). – kimbo Jan 30 '20 at 02:59