You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The {ps} package provides a means to get LISTENING port info in a cross-platform way. e.g.
library(ps)
lapply(ps()$ps_handle, function(x) {
tryCatch(ps_connections(x), error=function(x) NULL) # more on the need for this after the code block
}) ->resres<-res[lengths(res) >0] # some return values of `ps_connections()` are non-existentres<-res[sapply(res, nrow) >0] # and some are empty data framesres<- do.call(rbind.data.frame, res) # now make a dfres<-res[which((res$family%in% c("AF_INET", "AF_INET6")) & (res$state=="CONN_LISTEN")),] # and focus on network things
sort(res$lport)
## [1] 2600 3283 6000 6000 6372 7473 7474 7687 9222 9222 11199 11781 16662 ## [24] 17500 17500 17600 17603 25757 26482 26510 49162 49162 49202 49282 49282 49313
Unlike netstat, R is not "blessed" by the OS (certain systems, like macOS, make exceptions for some longstanding utilities) so R doesn't have default permissions to get LISTENING ports like netstat does without help.
Running the same thing with an R session started with sudo the same code above returns the following on my currently running system:
Granted, that's more painful than relying on netstat's blessed behavior, but it alleviates the need to parse netstat output in other locales and might be a useful alternative function.
The text was updated successfully, but these errors were encountered:
The
{ps}
package provides a means to getLISTENING
port info in a cross-platform way. e.g.Unlike
netstat
, R is not "blessed" by the OS (certain systems, like macOS, make exceptions for some longstanding utilities) so R doesn't have default permissions to getLISTENING
ports likenetstat
does without help.Running the same thing with an R session started with
sudo
the same code above returns the following on my currently running system:Granted, that's more painful than relying on
netstat
's blessed behavior, but it alleviates the need to parsenetstat
output in other locales and might be a useful alternative function.The text was updated successfully, but these errors were encountered: