MyNixOS website logo
Description

Check if a Remote Computer is Up.

Check if a remote computer is up. It can either just call the system ping command, or check a specified TCP port.

R-CMD-check Codecov test coverage CRAN RStudio mirror downloads

pingr: check if a server is alive

The pingr package has tools to check if a remote computer or web server is up and some other related tools.

Installation

Install the package from CRAN:

install.packages("pingr")

If you need the development version, install it from GitHub:

pak::pak("r-lib/pingr")

ICMP ping

The ping() function does ICMP ping, via the system's ping utility:

library(pingr)
#> 
#> Attaching package: 'pingr'
#> The following object is masked from 'package:utils':
#> 
#>     nsl
ping("127.0.0.1")
#> [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:

ping("127.0.0.1", count = 1)
#> [1] 0.182

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

TCP ping

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] 19.228

Query the public IP address of the computer

my_ip() queries the public IP of the computer, either via DNS or HTTPS:

my_ip()
#> [1] "83.50.96.133"

Check if the computer is online

is_online() checks if the computer is online. It makes three tries:

  • 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.

is_online()
#> [1] TRUE

DNS queries

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)
#> $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
nsl("google.com", type = 28L)
#> $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

License

MIT © RStudio.

Metadata

Version

2.0.3

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows