forked from r-lib/pingr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
87 lines (60 loc) · 2.1 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
```{r, setup, echo = FALSE, message = FALSE}
knitr::opts_chunk$set(
comment = "#>",
tidy = FALSE,
error = FALSE,
fig.width = 8,
fig.height = 8)
```
# pingr: check if a server is alive
[![Linux Build Status](https://travis-ci.org/r-lib/pingr.svg?branch=master)](https://travis-ci.org/r-lib/pingr)
[![Windows Build status](https://ci.appveyor.com/api/projects/status/github/r-lib/pingr?svg=true)](https://ci.appveyor.com/project/gaborcsardi/pingr)
[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/pingr)](https://r-pkg.org/pkg/pingr)
The pingr package has tools to check if a remote computer or web server is
up and some other related tools.
## ICMP ping
The `ping()` function does ICMP ping, via the system's `ping` utility:
```{r}
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:
```{r}
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:
```{r}
ping("192.0.2.1", count = 1)
```
## 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:
```{r}
ping_port("www.google.com", port = 80, count = 1)
```
## Query the public IP address of the computer
`my_ip()` queries the public IP of the computer, either via DNS or HTTPS:
```{r}
my_ip()
```
## 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`.
```{r}
is_online()
```
## 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:
```{r}
nsl("www.r-project.org", type = 1L)
nsl("google.com", type = 28L)
```
## License
MIT © RStudio