resolveWithSystemResolver method

Future<DnsTestResult> resolveWithSystemResolver({
  1. required String domain,
  2. Duration? timeout,
})

使用系统解析器解析域名 / Resolves a domain through the platform resolver.

Implementation

Future<DnsTestResult> resolveWithSystemResolver({
  required String domain,
  Duration? timeout,
}) async {
  final stopwatch = Stopwatch()..start();
  try {
    final addresses = await InternetAddress.lookup(
      domain,
    ).timeout(timeout ?? defaultTimeout);
    stopwatch.stop();
    return DnsTestResult(
      server: 'system',
      domain: domain,
      isSuccess: addresses.isNotEmpty,
      responseTime: stopwatch.elapsed,
      resolvedIps: addresses
          .map((address) => address.address)
          .toList(growable: false),
      timestamp: DateTime.now(),
      errorMessage: addresses.isEmpty ? 'No address returned' : null,
    );
  } catch (error) {
    stopwatch.stop();
    return DnsTestResult(
      server: 'system',
      domain: domain,
      isSuccess: false,
      responseTime: stopwatch.elapsed,
      errorMessage: error.toString(),
      timestamp: DateTime.now(),
    );
  }
}