HTTP::Online - Detect full "Internet" (HTTP) access using Microsoft NCSI
if ( HTTP::Online->new->online ) { print "Confirmed internet connection\n"; } else { print "Internet is not available\n"; exit(0); } # Now do your task that needs the internet...
HTTP::Online is a port of the older LWP::Online module to HTTP::Tiny that uses only the (most accurate) methodology, Microsoft NCSI.
use LWP::Online ':skip_all';
As a convenience when writing tests scripts base on Test::More, the special ':skip_all' param can be provided when loading LWP::Online.
This implements the functional equivalent of the following.
BEGIN { unless ( HTTP::Online->new->online ) { require Test::More; Test::More->import( skip_all => 'Test requires a working internet connection' ); } }
my $internet = HTTP::Online->new; my $custom = HTTP::Online->new( http => $custom_http_client, url => 'http://my-ncsi-server.com/', content => 'Our Custom NCSI Server', );
The new constructor creates a query object.
new
By default, it will be configured to use the same Microsoft NCSI service that the Windows Network Awareness system does (from Windows Vista onwards).
Returns a HTTP::Online object.
The http method returns the HTTP client that will be used for the query.
http
The url method returns a string with the location URL of the NCSI file.
url
The content method returns a string with the expected string to be returned from the NCSI server.
content
The online method issues a Pragma: no-cache request to the server, and examines the response to confirm that no redirects have occurred, and that the returned content matches the expected value.
online
Pragma: no-cache
Returns true if full HTTP internet access is available, or false otherwise.
The offline method is a convenience which currently returns the opposite of the online method, returning false if full HTTP internet access is available, or true otherwise.
offline
This may change in future to only return true if we are completely offline, and true in situations where we have partial internet access or the user needs to fill out some web form or view advertising to get full internet access.
Bugs should be reported via the CPAN bug tracker at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTTP-Online
For other issues, contact the author.
Adam Kennedy <adamk@cpan.org>
LWP::Online
HTTP::Tiny
http://technet.microsoft.com/en-us/library/cc766017.aspx
Copyright 2012 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
To install HTTP::Online, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::Online
CPAN shell
perl -MCPAN -e shell install HTTP::Online
For more information on module installation, please visit the detailed CPAN module installation guide.