knitr::opts_chunk$set( comment = "#>", tidy = FALSE, error = FALSE, fig.width = 8, fig.height = 8)
The pingr package has tools to check if a remote computer or web server is up and some other related tools.
Install the package from CRAN:
install.packages("pingr")
If you need the development version, install it from GitHub:
pak::pak("r-lib/pingr")
The ping()
function does ICMP ping, via the system's ping
utility:
library(pingr) ping("127.0.0.1")
By default it sends three packets and measures the time it receives and answer. It waits between sending out the packets, so if you want a really quick check, you can just send a single packet:
ping("127.0.0.1", count = 1)
If a machine is down (or it does not exist), then NA
is returned instead
of the roundtrip time:
ping("192.0.2.1", count = 1)
With TCP ping we can check if a machine is listeing on a TCP port, e.g. if google's search web server is up and running:
ping_port("www.google.com", port = 80, count = 1)
my_ip()
queries the public IP of the computer, either via DNS or HTTPS:
my_ip()
is_online()
checks if the computer is online. It makes three tries:
my_ip()
.my_ip()
.apple_captive_test()
.If any of these are successful, it returns TRUE
.
is_online()
The package also contains a function to perform DNS queries. This is a
more portable and more functional version of the utils::nsl()
function:
nsl("www.r-project.org", type = 1L) nsl("google.com", type = 28L)
MIT © RStudio
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.