Browse Source

airport scanning

master
boB Rudis 6 years ago
parent
commit
e9fa5c25f9
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 1
      .gitignore
  2. 2
      NAMESPACE
  3. 60
      R/airport-scan.R
  4. 2
      R/mactheknife-package.R
  5. 8
      README.Rmd
  6. 21
      README.md
  7. 17
      man/airport_scan.Rd

1
.gitignore

@ -6,3 +6,4 @@
src/*.o src/*.o
src/*.so src/*.so
src/*.dll src/*.dll
README_cache

2
NAMESPACE

@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand # Generated by roxygen2: do not edit by hand
export(airport_scan)
export(kernel_state) export(kernel_state)
export(read_dsstore) export(read_dsstore)
export(software_update_history) export(software_update_history)
@ -11,5 +12,6 @@ import(xml2)
importFrom(anytime,anytime) importFrom(anytime,anytime)
importFrom(purrr,"%>%") importFrom(purrr,"%>%")
importFrom(purrr,flatten_chr) importFrom(purrr,flatten_chr)
importFrom(purrr,map_chr)
importFrom(purrr,map_df) importFrom(purrr,map_df)
importFrom(purrr,set_names) importFrom(purrr,set_names)

60
R/airport-scan.R

@ -0,0 +1,60 @@
#' Scan for available wireless network (requires Wi-Fi enabled Mac)
#'
#' @md
#' @param .quiet if `TRUE` then no progress messages will be displayed
#' @note that we have to use the characater output since the XML output is broken on Sierra.
#' @export
airport_scan <- function(.quiet=FALSE) {
message("Scanning for available wireless networks...")
sys::exec_internal(
"/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport",
"-s"
) -> res
if (length(res$stdout) == 0) {
stop('Error scanning for networks Are you running on a Wi-Fi-enables macOS system?', call.=FALSE)
}
out <- rawToChar(res$stdout)
out <- strsplit(out, "[\r\n]+")[[1]]
out <- gsub("[\r\n]", "", out)
rl <- rle(strsplit(gsub("[[A-Z]", "X", out[1]), "")[[1]])
ssid_len <- sum(rl$lengths[1:3])
bssid_len <- sum(rl$lengths[4:5])
rssi_len <- sum(rl$lengths[6:7])
channel_len <- sum(rl$lengths[8:9])
ht_len <- sum(rl$lengths[10:11])
cc_len <- sum(rl$lengths[12:13])
security_start <- ssid_len + bssid_len + rssi_len + channel_len + ht_len + cc_len + 1
saf <- default.stringsAsFactors()
on.exit(options(stringsAsFactors = saf))
options(stringsAsFactors = FALSE)
con <- textConnection(paste0(out[2:length(out)], collaspe="\n"))
read.fwf(
file = con,
widths = c(ssid_len, bssid_len, rssi_len, channel_len, ht_len, cc_len),
stringsAsFactors = FALSE
) -> xdf
close(con)
xdf <- xdf[complete.cases(xdf),]
xdf[] <- lapply(xdf, trimws)
xdf <- type.convert(xdf, as.is=TRUE)
xdf$security <-
purrr::map_chr(out[2:length(out)], ~{
substr(.x, security_start, nchar(.x))
}) %>% trimws()
colnames(xdf) <- c("ssid", "bssid", "rssi", "channel", "ht", "cc", "security")
class(xdf) <- c("tbl_df", "tbl", "data.frame")
xdf
}

2
R/mactheknife-package.R

@ -7,6 +7,6 @@
#' @docType package #' @docType package
#' @author Bob Rudis (bob@@rud.is) #' @author Bob Rudis (bob@@rud.is)
#' @import reticulate sys xml2 #' @import reticulate sys xml2
#' @importFrom purrr map_df %>% flatten_chr set_names #' @importFrom purrr map_df %>% flatten_chr set_names map_chr
#' @importFrom anytime anytime #' @importFrom anytime anytime
NULL NULL

8
README.Rmd

@ -16,6 +16,7 @@ A set of tools/methods and data that are geared towards the 'macOS' ecosystem.
## What's Inside The Tin ## What's Inside The Tin
- `airport_scan`: Scan for available wireless network (requires Wi-Fi enabled Mac)
- `kernel_state`: Retrieve kernel state information - `kernel_state`: Retrieve kernel state information
- `read_dsstore`: Read a '.DS_Store' from a file/URL - `read_dsstore`: Read a '.DS_Store' from a file/URL
- `software_update_history`: Retrieve Software Update history - `software_update_history`: Retrieve Software Update history
@ -95,3 +96,10 @@ software_update_history()
```{r} ```{r}
sw_vers() sw_vers()
``` ```
### Airport scan
```{r airport, cache=TRUE}
airport_scan()
```

21
README.md

@ -14,6 +14,8 @@ ecosystem.
## What’s Inside The Tin ## What’s Inside The Tin
- `airport_scan`: Scan for available wireless network (requires Wi-Fi
enabled Mac)
- `kernel_state`: Retrieve kernel state information - `kernel_state`: Retrieve kernel state information
- `read_dsstore`: Read a ‘.DS\_Store’ from a file/URL - `read_dsstore`: Read a ‘.DS\_Store’ from a file/URL
- `software_update_history`: Retrieve Software Update history - `software_update_history`: Retrieve Software Update history
@ -154,3 +156,22 @@ sw_vers()
## ProductName ProductVersion BuildVersion ## ProductName ProductVersion BuildVersion
## <chr> <chr> <chr> ## <chr> <chr> <chr>
## 1 Mac OS X 10.12.6 16G1405 ## 1 Mac OS X 10.12.6 16G1405
### Airport scan
``` r
airport_scan()
```
## Scanning for available wireless networks...
## # A tibble: 7 x 7
## ssid bssid rssi channel ht cc security
## * <chr> <chr> <int> <chr> <chr> <chr> <chr>
## 1 RDN-5G 46:d9:e7:b3:80:47 -66 11 Y -- WPA2(PSK,FT-PSK/AES/AES)
## 2 RDN-100 56:d9:e7:b3:80:47 -72 11 Y -- WPA2(PSK,FT-PSK/AES/AES)
## 3 xfinitywifi 6e:e3:0e:49:32:3d -91 6 Y US NONE
## 4 shortcircut21 5c:e3:0e:49:32:3d -91 6 Y US WPA(PSK/AES,TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP)
## 5 H20man-guest c2:56:27:62:a7:33 -87 1,+1 Y -- NONE
## 6 RDN-5G 46:d9:e7:7b:9e:25 -51 1 Y -- WPA2(PSK,FT-PSK/AES/AES)
## 7 RDN-100 56:d9:e7:7b:9e:25 -52 1 Y -- WPA2(PSK,FT-PSK/AES/AES)

17
man/airport_scan.Rd

@ -0,0 +1,17 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/airport-scan.R
\name{airport_scan}
\alias{airport_scan}
\title{Scan for available wireless network (requires Wi-Fi enabled Mac)}
\usage{
airport_scan(.quiet = FALSE)
}
\arguments{
\item{.quiet}{if \code{TRUE} then no progress messages will be displayed}
}
\description{
Scan for available wireless network (requires Wi-Fi enabled Mac)
}
\note{
that we have to use the characater output since the XML output is broken on Sierra.
}
Loading…
Cancel
Save