dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.24k stars 1.57k forks source link

Add DNS Client to dart:io #22755

Open DartBot opened 9 years ago

DartBot commented 9 years ago

This issue was originally filed by @kaendfinger


NodeJS provides a DNS module that allows you to lookup records on domains. Dart should provide this functionality out of the box.

See https://nodejs.org/api/dns.html

Justification:

Some developers may want to write something like a thing to check if a domain has a TXT record. How would a developer do this now:

Solution: Implement a DNS Client API in dart:io

floitschG commented 9 years ago

Added Area-Library, Library-IO, Triaged labels.

lrhn commented 9 years ago

Seems like something that can reasonably be put in a separate package.

sgjesse commented 9 years ago

I think a DNS client implementation can be done as a package using dart:io

lrhn commented 9 years ago

Can the lookups be done using OS calls? If so, the functionality would fit into dart:io. If it needs to send UDP packets to a server, it might as well be done in a dns-client package (but then dart:io might still want to provide the IP address of the DNS server of the system).

DartBot commented 9 years ago

This comment was originally written by @kaendfinger


I believe it is done via OS calls, well, native library calls.

Linux: http://linux.die.net/man/3/res_query

I'm not sure about other platforms yet.

Ephenodrom commented 5 years ago

Hello ! Is there are solution for this ? At the moment i need to check the TXT record from a certain domain.

Any idea how to solve this or is there something like dnsjava?

Ephenodrom commented 5 years ago

Since it will take even longer for this function to be implemented, I have written a small helper class that can be used to query a record. It uses the google dns resolver api to fetch the records. I added this helper class to my helper class collection :

https://github.com/Ephenodrom/Dart-Basic-Utils

Add the following line to your pubspec.yaml

dependencies:
  basic_utils: ^1.0.6

Usage :

List<RRecord> records = await DnsUtils.lookupRecord("google.de", RRecordType.TXT);

Since it uses the google api, it should also work with the flutter framework!

InterNetX-DL commented 5 years ago
List<RRecord> records = await DnsUtils.lookupRecord("google.de", RRecordType.TXT);

Works like a charm!

0x1af2aec8f957 commented 1 year ago
InternetAddress.lookup('github.com').then((value) {
      value.forEach((element) async {
        print('element.address: ${element.address}');
      });
    });
yvs2014 commented 1 year ago
InternetAddress.lookup('github.com').then((value) {
      value.forEach((element) async {
        print('element.address: ${element.address}');
      });
    });

Is there a way to cancel dns request (or more precicelly - to close its socket) while it's in progress?

0x1af2aec8f957 commented 1 year ago

@yvs2014 Both the method of canceling Future and the method of canceling future still apply. You can refer to: https://stackoverflow.com/questions/17552757/is-there-any-way-to-cancel-a-dart-future

yvs2014 commented 1 year ago

@0x1af2aec8f957 does cancelling Future close underlying sockets opened at resolving?

0x1af2aec8f957 commented 1 year ago

@yvs2014 This method only cancels the final result, and Dart lacks relevant documentation for closing or canceling the underlying socket.

yvs2014 commented 1 year ago

@0x1af2aec8f957 so, in this case it's not helpful, because that async operation will continue. The ways known to me how to enforce closing underlying sockets: [1] close app with exit(3), but it's not always acceptable [2] place lookup calls into a separate thread (with isolate for ex), and kill that thread (as a variety of [1])

Just tried to find out a bit more direct and easy way how to close them