Skip to contents

Extracts every MAC-48 address found in txt. Supports the usual notations: colon (1C:4C:7E:30:D8:13), hyphen (1C-4C-7E-30-D8-13) and Cisco dotted (1C4C.7E30.D813). The separator must be the same inside each address, and longer hexadecimal sequences (e.g. EUI-64 or IPv6) are not partially matched.

Usage

search_MAC(
  txt,
  sep = c(":", "-"),
  dotted = TRUE,
  normalize = FALSE,
  unique = FALSE
)

Arguments

txt

A character vector with the text to search.

sep

A character vector with the allowed single-character separators. Use character() to search only the dotted notation.

dotted

Logical. Also search Cisco dotted notation (xxxx.xxxx.xxxx)?

normalize

Logical. If TRUE, results are returned in canonical XX:XX:XX:XX:XX:XX form (see normalize_MAC()); otherwise they are returned as found, in upper case.

unique

Logical. Remove duplicated addresses?

Value

A character vector with the MAC addresses found (possibly empty).

Examples

sample_txt <- "MAC addresses 1C:4C:7E:30:d8:13 and 00-1A-2B-3C-4D-5E"
search_MAC(sample_txt)
#> [1] "1C:4C:7E:30:D8:13" "00-1A-2B-3C-4D-5E"
search_MAC(sample_txt, normalize = TRUE)
#> [1] "1C:4C:7E:30:D8:13" "00:1A:2B:3C:4D:5E"
search_MAC("Cisco style: 001a.2b3c.4d5e")
#> [1] "001A.2B3C.4D5E"