Learn R Programming

Ecfun (version 0.1-4)

Ping: ping a Uniform resource locator (URL)

Description

***NOTE: THIS IS A PRELIMINARY VERSION OF THIS FUNCTION; ***NOTE: IT MAY BE CHANGED OR REMOVED IN A FUTURE RELEASE. ping a Uniform resource locator (URL) or Internet Protocol (IP) address. NOTE: Some Internet Service Providers (ISPs) play games with "ping". That makes the results of Ping unreliable.

Usage

Ping(url, pingArgs='', warn=NA,
     show.output.on.console=FALSE)

Arguments

url
a character string of a URL or IP address to ping. If url is a vector of length greater than 1, only the first component is used.
pingArgs
arguments to pass to the ping command of typical operating systems via pingResult <- system(paste('ping', pingArgs, url), intern=TRUE, ...)
warn
value for options('warn') during the call to system. NA to not change options('warn') during this call.
show.output.on.console
argument for system.

Value

  • list with the following components:
  • rawResultscharacter vector of the raw results from the ping command
  • rawNumbersnumeric vector of the times measured
  • countsnumeric vector of numbers of packets sent, received, and lost
  • p.lostproportion lost = lost / sent
  • statsnumeric vector of min, avg (mean), max, and mdev (standard deviation) of the measured round trip times

Details

1. urlSplit0 <- strsplit(url, '://')[[1]] 2. urlS0 <- urlSplit0[min(2, length(urlSplit0))] 3. host <- strsplit(urlS0, '/')[[1]][1] 4. pingCmd <- paste('ping', pingArgs, host) 5. system(pingCmd, intern=TRUE, ...)

See Also

system, options

Examples

Run this code
##
## Some ISPs play games with ping.
## Therefore, the results are not reliable.
##
##
## good
##
(google <- Ping('http://google.com/ping works on host not pages'))

\dontshow{stopifnot(}
with(google, (counts[1]>0) && (counts[3]<1))
\dontshow{)}

##
## ping oops <<-- at one time, this failed.
##      However, with some ISPs, it works, so don't test it.
##

##
(couldnotfindhost <- Ping('oops'))

\dontshow{stopifnot(}
with(couldnotfindhost,
     length(grep('could not find host', rawResults))>0)
\dontshow{)}

##
## impossible, but not so obvious
##
(requesttimedout <- Ping('requesttimedout.com'))

\dontshow{stopifnot(}
with(requesttimedout, (counts[1]>0) && (counts[2]<1) &&
         (counts[3]>0))
\dontshow{)}

Run the code above in your browser using DataLab