From 353c79f6f7197586457babfc14582367e56378eb Mon Sep 17 00:00:00 2001 From: hrbrmstr Date: Tue, 27 Jul 2021 06:56:45 -0400 Subject: [PATCH] README/test/workflow --- .github/workflows/R-CMD-check.yaml | 14 +++-- NAMESPACE | 2 + R/packet-sum.R | 5 +- R/tshark-hosts.R | 5 +- R/tsharrk-package.R | 2 +- README.Rmd | 12 +++++ README.md | 107 +++++++++++++++++++++++++++++++++++++ inst/tinytest/test_tsharrk.R | 16 +++++- man/packet_summary.Rd | 5 +- man/tshark_hosts.Rd | 5 +- 10 files changed, 163 insertions(+), 10 deletions(-) create mode 100644 README.md diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 1c1942e..7c3e8b1 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -12,15 +12,23 @@ name: R-CMD-check jobs: R-CMD-check: - runs-on: macOS-latest + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@master + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Setup R + uses: r-lib/actions/setup-r@v1 + + - name: Install tshark + run: sudo apt install -y libcurl4-openssl-dev libgmp-dev libxml2-dev libglpk-dev tshark + - name: Install dependencies run: | install.packages(c("remotes", "rcmdcheck")) remotes::install_deps(dependencies = TRUE) shell: Rscript {0} + - name: Check run: rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "error") shell: Rscript {0} diff --git a/NAMESPACE b/NAMESPACE index ff020c8..2233680 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,3 +11,5 @@ importFrom(tools,file_ext) importFrom(tools,file_path_sans_ext) importFrom(utils,browseURL) importFrom(utils,help) +importFrom(utils,read.csv) +importFrom(utils,tail) diff --git a/R/packet-sum.R b/R/packet-sum.R index 2997b7f..b89e2a8 100644 --- a/R/packet-sum.R +++ b/R/packet-sum.R @@ -4,7 +4,10 @@ #' @return data frame #' @export #' @examples -#' packet_summary(system.file("pcap", "http.pcap", package = "tsharrk")) +#' tryCatch( +#' packet_summary(system.file("pcap", "http.pcap", package = "tsharrk")), +#' error = function(e) message("No tshark") +#' ) packet_summary <- function(pcap) { pcap <- path.expand(pcap[1]) diff --git a/R/tshark-hosts.R b/R/tshark-hosts.R index ad17671..2552d7d 100644 --- a/R/tshark-hosts.R +++ b/R/tshark-hosts.R @@ -4,7 +4,10 @@ #' @return data frame #' @export #' @examples -#' tshark_hosts(system.file("pcap", "http.pcap", package = "tsharrk")) +#' tryCatch( +#' tshark_hosts(system.file("pcap", "http.pcap", package = "tsharrk")), +#' error = function(e) message("No tshark") +#' ) tshark_hosts <- function(pcap) { pcap <- path.expand(pcap[1]) diff --git a/R/tsharrk-package.R b/R/tsharrk-package.R index c97dc26..9dcfdab 100644 --- a/R/tsharrk-package.R +++ b/R/tsharrk-package.R @@ -11,6 +11,6 @@ #' @author Bob Rudis (bob@@rud.is) #' @import arrow #' @import ndjson -#' @importFrom utils browseURL help +#' @importFrom utils browseURL help read.csv tail #' @importFrom tools file_path_sans_ext file_ext "_PACKAGE" diff --git a/README.Rmd b/README.Rmd index 3ae8c6e..0db10a1 100644 --- a/README.Rmd +++ b/README.Rmd @@ -45,6 +45,18 @@ packageVersion("tsharrk") cloc::cloc_pkg_md() ``` +```{r ex-01} +tshark_hosts(system.file("pcap", "http.pcap", package = "tsharrk")) +``` + +```{r ex-02} +library(tibble) + +as_tibble( + packet_summary(system.file("pcap", "http.pcap", package = "tsharrk")) +) +``` + ## Code of Conduct Please note that this project is released with a Contributor Code of Conduct. diff --git a/README.md b/README.md new file mode 100644 index 0000000..018d5ca --- /dev/null +++ b/README.md @@ -0,0 +1,107 @@ + +[![Project Status: Active – The project has reached a stable, usable +state and is being actively +developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) +[![Signed +by](https://img.shields.io/badge/Keybase-Verified-brightgreen.svg)](https://keybase.io/hrbrmstr) +![Signed commit +%](https://img.shields.io/badge/Signed_Commits-100%25-lightgrey.svg) +[![R-CMD-check](https://github.com/hrbrmstr/tsharrk/workflows/R-CMD-check/badge.svg)](https://github.com/hrbrmstr/tsharrk/actions?query=workflow%3AR-CMD-check) +[![Linux build +Status](https://travis-ci.org/hrbrmstr/tsharrk.svg?branch=master)](https://travis-ci.org/hrbrmstr/tsharrk) +[![Coverage +Status](https://codecov.io/gh/hrbrmstr/tsharrk/branch/master/graph/badge.svg)](https://codecov.io/gh/hrbrmstr/tsharrk) +![Minimal R +Version](https://img.shields.io/badge/R%3E%3D-3.6.0-blue.svg) +![License](https://img.shields.io/badge/License-AGPL-blue.svg) + +# tsharrk + +Tools to Make Analyses Using ‘tshark’ Easier + +## Description + +The ‘tshark’ () +command line utility comes with Wireshark and is a is useful when +performing analyses on packet captures (PCAPs). Tools are provided to +make it a bit easier to work with ‘tshark’ to perform analyses with R. + +## What’s Inside The Tin + +The following functions are implemented: + +- `find_tshark`: Find the tshark binary +- `get_tshark`: Get tshark +- `packet_summary`: Extract packet summary table (if any) from a PCAP +- `tshark_exec`: Call the tshark binary with optional custom + environment variables and options +- `tshark_hosts`: Extract hostname/IP table (if any) from a PCAP + +## Installation + +``` r +remotes::install_git("https://git.rud.is/hrbrmstr/tsharrk.git") +# or +remotes::install_gitlab("hrbrmstr/tsharrk") +# or +remotes::install_github("hrbrmstr/tsharrk") +``` + +NOTE: To use the ‘remotes’ install options you will need to have the +[{remotes} package](https://github.com/r-lib/remotes) installed. + +## Usage + +``` r +library(tsharrk) + +# current version +packageVersion("tsharrk") +## [1] '0.1.0' +``` + +## tsharrk Metrics + +| Lang | # Files | (%) | LoC | (%) | Blank lines | (%) | # Lines | (%) | +|:-----|--------:|-----:|----:|-----:|------------:|-----:|--------:|-----:| +| R | 7 | 0.35 | 108 | 0.36 | 33 | 0.29 | 65 | 0.33 | +| YAML | 2 | 0.10 | 27 | 0.09 | 6 | 0.05 | 2 | 0.01 | +| Rmd | 1 | 0.05 | 13 | 0.04 | 18 | 0.16 | 32 | 0.16 | +| SUM | 10 | 0.50 | 148 | 0.50 | 57 | 0.50 | 99 | 0.50 | + +clock Package Metrics for tsharrk + +``` r +tshark_hosts(system.file("pcap", "http.pcap", package = "tsharrk")) +## ip host +## 1 216.239.59.104 pagead.google.akadns.net +## 2 216.239.59.99 pagead.google.akadns.net +``` + +``` r +library(tibble) + +as_tibble( + packet_summary(system.file("pcap", "http.pcap", package = "tsharrk")) +) +## # A tibble: 43 x 7 +## packet_num ts src dst proto length info +## +## 1 1 0 145.254.160… 65.208.228.… TCP 62 "3372 → 80 [SYN] Seq=0 Win=8760 Len=0 MSS=1460 SACK_PERM=1" +## 2 2 0.911 65.208.228.… 145.254.160… TCP 62 "80 → 3372 [SYN, ACK] Seq=0 Ack=1 Win=5840 Len=0 MSS=1380 SA… +## 3 3 0.911 145.254.160… 65.208.228.… TCP 54 "3372 → 80 [ACK] Seq=1 Ack=1 Win=9660 Len=0" +## 4 4 0.911 145.254.160… 65.208.228.… HTTP 533 "GET /download.html HTTP/1.1 " +## 5 5 1.47 65.208.228.… 145.254.160… TCP 54 "80 → 3372 [ACK] Seq=1 Ack=480 Win=6432 Len=0" +## 6 6 1.68 65.208.228.… 145.254.160… TCP 1434 "HTTP/1.1 200 OK [TCP segment of a reassembled PDU]" +## 7 7 1.81 145.254.160… 65.208.228.… TCP 54 "3372 → 80 [ACK] Seq=480 Ack=1381 Win=9660 Len=0" +## 8 8 1.81 65.208.228.… 145.254.160… TCP 1434 "80 → 3372 [ACK] Seq=1381 Ack=480 Win=6432 Len=1380 [TCP seg… +## 9 9 2.01 145.254.160… 65.208.228.… TCP 54 "3372 → 80 [ACK] Seq=480 Ack=2761 Win=9660 Len=0" +## 10 10 2.44 65.208.228.… 145.254.160… TCP 1434 "80 → 3372 [ACK] Seq=2761 Ack=480 Win=6432 Len=1380 [TCP seg… +## # … with 33 more rows +``` + +## Code of Conduct + +Please note that this project is released with a Contributor Code of +Conduct. By participating in this project you agree to abide by its +terms. diff --git a/inst/tinytest/test_tsharrk.R b/inst/tinytest/test_tsharrk.R index aa3f72e..8772bc9 100644 --- a/inst/tinytest/test_tsharrk.R +++ b/inst/tinytest/test_tsharrk.R @@ -1,4 +1,16 @@ +library(tsharrk) -# Placeholder with simple test -expect_equal(1 + 1, 2) +loc <- tryCatch( + find_tshark(), + error = function(e) message("No tshark") +) +tryCatch( + tshark_hosts(system.file("pcap", "http.pcap", package = "tsharrk")), + error = function(e) message("No tshark") +) + +tryCatch( + packet_summary(system.file("pcap", "http.pcap", package = "tsharrk")), + error = function(e) message("No tshark") +) \ No newline at end of file diff --git a/man/packet_summary.Rd b/man/packet_summary.Rd index 414a61f..f7b1a40 100644 --- a/man/packet_summary.Rd +++ b/man/packet_summary.Rd @@ -16,5 +16,8 @@ data frame Extract packet summary table (if any) from a PCAP } \examples{ -packet_summary(system.file("pcap", "http.pcap", package = "tsharrk")) +tryCatch( + packet_summary(system.file("pcap", "http.pcap", package = "tsharrk")), + error = function(e) message("No tshark") +) } diff --git a/man/tshark_hosts.Rd b/man/tshark_hosts.Rd index 25a1788..63ea906 100644 --- a/man/tshark_hosts.Rd +++ b/man/tshark_hosts.Rd @@ -16,5 +16,8 @@ data frame Extract hostname/IP table (if any) from a PCAP } \examples{ -tshark_hosts(system.file("pcap", "http.pcap", package = "tsharrk")) +tryCatch( + tshark_hosts(system.file("pcap", "http.pcap", package = "tsharrk")), + error = function(e) message("No tshark") +) }