Skip to content

Commit

Permalink
is_online() tried the captive test first
Browse files Browse the repository at this point in the history
Closes #13.
  • Loading branch information
gaborcsardi committed Jun 22, 2020
1 parent 10fc787 commit e7cdc4f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# Development version

* `is_online()` now tries the Apple captive test first, because it works better
when DNS is not masked, but HTTP is (#13).

# 2.0.0

* New `nsl()` function to perform DNS queries.
Expand Down
10 changes: 5 additions & 5 deletions R/ping-package.r
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ ping_os <- function(destination, continuous, count, timeout) {
#' Is the computer online?
#'
#' Check if the computer is online. It does three tries:
#' * Retrieve Apple's Captive Portal test page, see [apple_captive_test()].
#' * Queries myip.opendns.com on OpenDNS, see [my_ip()].
#' * Retrieves icanhazip.com via HTTPS, see [my_ip()].
#' * Retrieve Apple's Captive Portal test page, see [apple_captive_test()].
#' If any of these are successful, it returns `TRUE`.
#'
#' @param timeout Timeout for the queries. (Note: it is currently not
Expand All @@ -156,17 +156,17 @@ is_online <- function(timeout = 1) {
on.exit(options(opts), add = TRUE)

tryCatch({
my_ip(method = "dns")
return(TRUE)
if (apple_captive_test()) return(TRUE)
}, error = function(e) NULL)

tryCatch({
my_ip(method = "https")
my_ip(method = "dns")
return(TRUE)
}, error = function(e) NULL)

tryCatch({
if (apple_captive_test()) return(TRUE)
my_ip(method = "https")
return(TRUE)
}, error = function(e) NULL)

FALSE
Expand Down
2 changes: 1 addition & 1 deletion man/is_online.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e7cdc4f

Please sign in to comment.