سؤال

I am new to scripting and R.

In the Windows cmd.exe I can perform an NSLOOKUP on a domain by:

nslookup www.google.com

I have a dataset of domain names that I would like to verify as valid or invalid as part of my grouping process in R. Is there a way to do NSLOOKUP in base R or one of the packages?

Edit1: I made some alterations to loop through 3 domains using the system call suggested. The call works, however the output will not save directly into a vector (line 7 below). How would I need to rework this line so that I can capture the output?

domains <- c('www.google.com','www.badtestdomainnotvalid.com','www.yahoo.com')
dns <- vector()
dnsreturn <-vector()
for(i in 1:length(domains)){
  dns[i] <- paste('nslookup ',domains[i],sep='')
  dnsreturn[i] <- system(dns[i],intern=TRUE)}
}
هل كانت مفيدة؟

المحلول

If nothing else you could do

system("nslookup www.google.com", intern=TRUE)

In response to your edit:

domains = c('www.google.com','www.badtestdomainnotvalid.com','www.yahoo.com')
sapply(domains, function(x) system(paste("nslookup", x), intern=TRUE))

This will return a list of vectors, you can manipulate as you see fit beyond that

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top