| Title: | Find, Validate and Identify Device MAC Addresses |
|---|---|
| Description: | Tools to work with MAC (Media Access Control) addresses: list the MAC addresses of the local network interfaces and of the neighbors in the ARP cache on Linux, macOS and Windows, extract MAC addresses from free text, validate and normalize their notation, check the multicast and locally administered bits, generate random addresses, derive IPv6 interface identifiers (modified EUI-64), and identify the manufacturer using the public IEEE (Institute of Electrical and Electronics Engineers) MA-L, MA-M and MA-S registries <https://regauth.standards.ieee.org/standards-ra-web/pub/view.html#registries>. |
| Authors: | Enrique Pérez Herrero [aut, cre] |
| Maintainer: | Enrique Pérez Herrero <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-10-24 21:08:10 UTC |
| Source: | https://github.com/cran/MAC.address |
Derives the IPv6 interface identifier from a MAC address, as used by
stateless address autoconfiguration (RFC 4291, appendix A): FF:FE is
inserted in the middle of the address and the U/L bit is inverted.
eui64_MAC(mac, link_local = FALSE)eui64_MAC(mac, link_local = FALSE)
mac |
A character vector of MAC addresses. |
link_local |
Logical. If |
A character vector in IPv6 notation (lower case, leading zeros
omitted, as recommended by RFC 5952). NA for invalid addresses.
eui64_MAC("1C:4C:7E:30:D8:13") eui64_MAC("1C:4C:7E:30:D8:13", link_local = TRUE)eui64_MAC("1C:4C:7E:30:D8:13") eui64_MAC("1C:4C:7E:30:D8:13", link_local = TRUE)
Lists the IPv4 neighbors (other devices in the local network) that this
machine has recently talked to, with their MAC addresses, as stored in the
operating system ARP cache. Combined with lookup_vendor(), it helps to
identify the devices in a network.
get_arp_table()get_arp_table()
Works on Linux (reads /proc/net/arp), macOS and other Unix systems
(parses arp -an) and Windows (parses arp -a). Only the existing cache is
read: no packets are sent, so devices that have not communicated with this
machine recently are not listed.
A data frame with columns ip, mac (normalized, see
normalize_MAC()) and interface (on Windows, the IP address of the
interface). Incomplete entries are dropped. If the table cannot be read,
a warning is given and a data frame with no rows is returned.
get_MAC() for the addresses of this device.
arp <- get_arp_table() head(arp) # Manufacturer of each neighbor (needs an internet connection once) oui <- try(get_oui_registry(cache_dir = tempdir())) if (is.data.frame(oui)) arp$vendor <- lookup_vendor(arp$mac, oui)arp <- get_arp_table() head(arp) # Manufacturer of each neighbor (needs an internet connection once) oui <- try(get_oui_registry(cache_dir = tempdir())) if (is.data.frame(oui)) arp$vendor <- lookup_vendor(arp$mac, oui)
Lists the hardware (MAC) address of each network interface of the local
machine. Works on Linux (reads /sys/class/net), macOS and other Unix
systems (parses ifconfig -a) and Windows (parses getmac).
get_MAC(include_null = FALSE)get_MAC(include_null = FALSE)
include_null |
Logical. Keep interfaces whose address is
|
A named character vector of normalized MAC addresses
(XX:XX:XX:XX:XX:XX), named by interface. If the addresses cannot be
read, a warning is given and an empty vector is returned.
get_MAC()get_MAC()
Downloads the public IEEE registries of MAC address blocks and combines them in one data frame. The result is cached on disk, so later calls do not need an internet connection.
get_oui_registry( registry = c("MA-L", "MA-M", "MA-S"), refresh = FALSE, cache_dir = NULL )get_oui_registry( registry = c("MA-L", "MA-M", "MA-S"), refresh = FALSE, cache_dir = NULL )
registry |
Which registries to download. |
refresh |
Logical. Download again even if a cached copy exists? |
cache_dir |
Directory where the CSV files are cached. By default, the
user cache directory given by To remove the cached files, delete the cache directory, e.g.
|
Registries:
MA-L: MAC Address Block Large (24-bit prefix, the classic OUI).
MA-M: MAC Address Block Medium (28-bit prefix).
MA-S: MAC Address Block Small (36-bit prefix).
A data frame with columns registry, assignment (hexadecimal
prefix), organization and address. If a registry cannot be downloaded
(e.g. no internet connection), an error with an informative message is
given.
# Needs an internet connection; the MA-L registry is about 4 MB oui <- try(get_oui_registry("MA-L", cache_dir = tempdir())) if (is.data.frame(oui)) head(oui)# Needs an internet connection; the MA-L registry is about 4 MB oui <- try(get_oui_registry("MA-L", cache_dir = tempdir())) if (is.data.frame(oui)) head(oui)
Locally administered addresses (e.g. randomized addresses used by phones for Wi-Fi privacy, or virtual machines) have the second least significant bit of the first octet set (the U/L bit).
is_local_MAC(mac)is_local_MAC(mac)
mac |
A character vector of MAC addresses. |
A logical vector (NA for invalid addresses).
is_multicast_MAC(), random_MAC()
is_local_MAC(c("02:00:00:00:00:01", "1C:4C:7E:30:D8:13"))is_local_MAC(c("02:00:00:00:00:01", "1C:4C:7E:30:D8:13"))
Check whether strings are valid MAC addresses
is_MAC(x)is_MAC(x)
x |
A character vector. |
A logical vector, TRUE where the whole string is a MAC address in
colon, hyphen or Cisco dotted notation.
is_MAC(c("1C:4C:7E:30:D8:13", "1C:4C:7E:30:D8", "1C:4C-7E:30:D8:13"))is_MAC(c("1C:4C:7E:30:D8:13", "1C:4C:7E:30:D8", "1C:4C-7E:30:D8:13"))
Multicast (group) addresses have the least significant bit of the first
octet set (the I/G bit). The broadcast address FF:FF:FF:FF:FF:FF is a
multicast address. Network interfaces always have unicast addresses.
is_multicast_MAC(mac)is_multicast_MAC(mac)
mac |
A character vector of MAC addresses. |
A logical vector (NA for invalid addresses).
is_multicast_MAC(c("01:00:5E:00:00:FB", "FF:FF:FF:FF:FF:FF", "1C:4C:7E:30:D8:13"))is_multicast_MAC(c("01:00:5E:00:00:FB", "FF:FF:FF:FF:FF:FF", "1C:4C:7E:30:D8:13"))
Looks up the organization that owns each MAC address block, using the longest matching prefix (MA-S, then MA-M, then MA-L).
lookup_vendor(mac, registry = get_oui_registry())lookup_vendor(mac, registry = get_oui_registry())
mac |
A character vector of MAC addresses in any supported notation. |
registry |
A data frame as returned by |
Locally administered addresses (see is_local_MAC()), such as randomized
Wi-Fi addresses, are not part of the IEEE registries and usually return NA.
A character vector with the organization names (NA if unknown).
# A small registry, to run without internet access registry <- data.frame( registry = c("MA-L", "MA-M"), assignment = c("00000C", "70B3D51"), organization = c("Cisco Systems, Inc", "Example Medium Co") ) macs <- c("00-00-0C-12-34-56", "70:B3:D5:1A:00:00", "02:00:00:00:00:01") lookup_vendor(macs, registry) # With the full IEEE registries (needs an internet connection) oui <- try(get_oui_registry(cache_dir = tempdir())) if (is.data.frame(oui)) lookup_vendor(get_MAC(), oui)# A small registry, to run without internet access registry <- data.frame( registry = c("MA-L", "MA-M"), assignment = c("00000C", "70B3D51"), organization = c("Cisco Systems, Inc", "Example Medium Co") ) macs <- c("00-00-0C-12-34-56", "70:B3:D5:1A:00:00", "02:00:00:00:00:01") lookup_vendor(macs, registry) # With the full IEEE registries (needs an internet connection) oui <- try(get_oui_registry(cache_dir = tempdir())) if (is.data.frame(oui)) lookup_vendor(get_MAC(), oui)
Converts MAC addresses written in any supported notation to a common upper-case format.
normalize_MAC(mac, sep = ":")normalize_MAC(mac, sep = ":")
mac |
A character vector of MAC addresses. |
sep |
Separator to use in the output. Use |
A character vector. Invalid addresses become NA.
normalize_MAC(c("1c-4c-7e-30-d8-13", "1c4c.7e30.d813", "not a MAC")) normalize_MAC("1C:4C:7E:30:D8:13", sep = "-")normalize_MAC(c("1c-4c-7e-30-d8-13", "1c4c.7e30.d813", "not a MAC")) normalize_MAC("1C:4C:7E:30:D8:13", sep = "-")
Generates random MAC addresses, e.g. for virtual machines, containers or
tests. By default they are locally administered unicast addresses, so they
never clash with addresses assigned by the IEEE to manufacturers. Uses R's
random number generator, so results can be reproduced with set.seed().
random_MAC(n = 1, local = TRUE, multicast = FALSE, sep = ":")random_MAC(n = 1, local = TRUE, multicast = FALSE, sep = ":")
n |
Number of addresses. |
local |
Logical. Set the locally administered bit (see
|
multicast |
Logical. Set the multicast bit (see |
sep |
Separator to use, as in |
A character vector of n MAC addresses.
set.seed(1) random_MAC(3) random_MAC(1, sep = "-")set.seed(1) random_MAC(3) random_MAC(1, sep = "-")
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.
search_MAC( txt, sep = c(":", "-"), dotted = TRUE, normalize = FALSE, unique = FALSE )search_MAC( txt, sep = c(":", "-"), dotted = TRUE, normalize = FALSE, unique = FALSE )
txt |
A character vector with the text to search. |
sep |
A character vector with the allowed single-character separators.
Use |
dotted |
Logical. Also search Cisco dotted notation ( |
normalize |
Logical. If |
unique |
Logical. Remove duplicated addresses? |
A character vector with the MAC addresses found (possibly empty).
sample_txt <- "MAC addresses 1C:4C:7E:30:d8:13 and 00-1A-2B-3C-4D-5E" search_MAC(sample_txt) search_MAC(sample_txt, normalize = TRUE) search_MAC("Cisco style: 001a.2b3c.4d5e")sample_txt <- "MAC addresses 1C:4C:7E:30:d8:13 and 00-1A-2B-3C-4D-5E" search_MAC(sample_txt) search_MAC(sample_txt, normalize = TRUE) search_MAC("Cisco style: 001a.2b3c.4d5e")