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:
If you need the development version, install it from GitHub:
The ping()
function does ICMP ping, via the system’s ping
utility:
#>
#> Attaching package: 'pingr'
#> The following object is masked from 'package:utils':
#>
#> nsl
#> [1] 0.087 0.301 0.206
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:
#> [1] 0.182
If a machine is down (or it does not exist), then NA
is returned instead of the roundtrip time:
#> [1] NA
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:
#> [1] 19.228
my_ip()
queries the public IP of the computer, either via DNS or HTTPS:
#> [1] "83.50.96.133"
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
.
#> [1] TRUE
The package also contains a function to perform DNS queries. This is a more portable and more functional version of the utils::nsl()
function:
#> $answer
#> name class type ttl data
#> 1 www.r-project.org 1 5 6525 cran.wu-wien.ac.at
#> 2 cran.wu-wien.ac.at 1 1 300 137.208.57.37
#>
#> $flags
#> aa tc rd ra ad cd
#> FALSE FALSE TRUE TRUE FALSE FALSE
#> $answer
#> name class type ttl data
#> 1 google.com 1 28 210 2a00:1450:4003:80f::200e
#>
#> $flags
#> aa tc rd ra ad cd
#> FALSE FALSE TRUE TRUE FALSE FALSE
MIT © RStudio