The pingr package is a simple utility that can be used to check if a remote machine is running, by sending network packets to it. It is similar to the command line ping
program, in fact for ICMP packages it just calls ping
.
The ping()
function does ICMP ping, via the system's ping
utility:
library(pingr)
ping("127.0.0.1")
#> [1] 0.055 0.061 0.123
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)
#> [1] 0.046
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)
#> [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:
ping_port("www.google.com", port = 80, count = 1)
#> [1] 78.884