The curl
package has a function has_internet
which tests by performing a nslookup
:
curl::has_internet
## function(){
## !is.null(nslookup("google.com", error = FALSE))
## }
Testing DNS is faster and may be more reliable than retrieving a URL because the latter might fail for unrelated reasons (e.g. firewall, server down, etc).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…