data_connection_checker 0.1.2 copy "data_connection_checker: ^0.1.2" to clipboard
data_connection_checker: ^0.1.2 copied to clipboard

outdated

Checks for an actual internet connection, by opening a socket connection to DNS Resolver addresses.

data_connection_checker #

Checks for an internet (data) connection, by opening a socket connection to DNS Resolver addresses to port 53.

The defaults of the plugin should be sufficient to reliably determine if the device is currently connected to the global network, e.i. has access to the Internet.

Quick start: #

// DataConnectionChecker accepts 3 named parameters,
// which can override the defaults.
// See the docs for more info.
var internetChecker = DataConnectionChecker();
bool result await internetChecker.hasDataConnection;
if(result == true) {
  print('YAY! Free cute dog pics!');
} else {
  print('No internet :( Reason:');
  print(internetChecker.lastTryLog);
}

Once the class is instantiated, there's no way to change the addresses/port/timeout. This is by design, but I'm open to discussion, just submit an issue on the official repository page.

Defaults #

The defaults are based on data collected from https://perfops.net/ (https://www.dnsperf.com/#!dns-resolvers) Here's some more info about it:

DEFAULT_ADDRESSES includes the top 3 globally available DNS resolvers:

1.1.1.1           CloudFlare, info: https://one.one.one.one/ http://1.1.1.1
8.8.4.4           Google, info: https://developers.google.com/speed/public-dns/
208.67.220.220    OpenDNS, info: https://use.opendns.com/
static const List<String> DEFAULT_ADDRESSES = [
  '1.1.1.1',
  '8.8.4.4',
  '208.67.220.220',
];

DEFAULT_PORT should always be 53

A DNS server listens for requests on port 53 (both UDP and TCP). So all DNS requests are sent to port 53 ...

More info here: https://www.google.com/search?q=dns+server+port

static const int DEFAULT_PORT = 53;

DEFAULT_TIMEOUT is 10 seconds, which can easily be overridden when instantiating the class.

Overriding the default timeout:

var _internetChecker = DataConnectionChecker(timeout: Duration(CUSTOM_TIMEOUT));

Usage #

Example:

import 'package:data_connection_checker/data_connection_checker.dart';

main() async {
  var internetChecker = DataConnectionChecker();
  print("The statement 'this machine is connected to the Internet' is: ");
  print(await internetChecker.hasDataConnection);

  print('---------\nlog from the last check:');
  print(internetChecker.lastTryLog);
}

See example folder for more examples.

License #

MIT

Copyright 2019 Kristiyan Mitev

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

425
likes
0
pub points
95%
popularity

Publisher

unverified uploader

Checks for an actual internet connection, by opening a socket connection to DNS Resolver addresses.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on data_connection_checker