Skip to content

Instantly share code, notes, and snippets.

@rmtbb
Last active April 10, 2025 05:44
Show Gist options
  • Save rmtbb/b9ecd7201c7caf925cd60be88cb43ffb to your computer and use it in GitHub Desktop.
Save rmtbb/b9ecd7201c7caf925cd60be88cb43ffb to your computer and use it in GitHub Desktop.
whereyallfrom by Remote BB - A handy ZSH command to look up MAC address vendors on your network — or any list of MACs you throw at it.
function whereyallfrom() {
OUI_FILE="$HOME/oui.txt"
if [[ ! -f "$OUI_FILE" ]]; then
echo "Error: $OUI_FILE not found!"
return 1
fi
clean_mac() {
echo "$1" | tr -d ':-.' | tr '[:lower:]' '[:upper:]'
}
lookup_mac() {
local mac="$1"
local ip="$2"
local cleaned=$(clean_mac "$mac")
local oui=${cleaned:0:6}
if [[ "$oui" == "FFFFFF" ]]; then
echo "$ip | $mac | <broadcast>"
return
fi
# Grab vendor line from (base 16) entries
vendor=$(grep -i "^$oui" "$OUI_FILE" | grep "(base 16)" | awk -F'\t' '{print $2}' | sed 's/^ *//;s/ *$//' | head -n 1)
if [[ -z "$vendor" ]]; then
echo "$ip | $mac | No vendor found"
else
echo "$ip | $mac | $vendor"
fi
}
# Print header
printf "%-16s | %-17s | %-30s\n" "IP Address" "MAC Address" "Vendor"
printf "%-16s-+-%-17s-+-%-30s\n" "----------------" "-----------------" "------------------------------"
if [ $# -eq 0 ]; then
# Parse arp -a output: grab IP and MAC pairs
arp -a | awk '/at/ {print $2, $4}' | sed 's/[()]//g' | while read -r ip mac; do
lookup_mac "$mac" "$ip"
done
else
for mac in "$@"; do
lookup_mac "$mac" "-"
done
fi
}
@rmtbb
Copy link
Author

rmtbb commented Apr 9, 2025

whereyallfrom by Remote BB

A handy ZSH command to look up MAC address vendors on your network — or any list of MACs you throw at it.


🚀 What it Does

  • Scans your local network (arp -a) for devices
  • Extracts their IP and MAC addresses
  • Uses a local OUI database (oui.txt) to determine vendor
  • Displays results in a clean, aligned table with:
    • IP Address
    • MAC Address
    • Vendor Name

🛠️ Setup

1. Download the OUI Database

Download the latest vendor list from the IEEE directly:

🔗 https://standards-oui.ieee.org/oui/oui.txt

Save the file as:

mv ~/Downloads/oui.txt ~/

This script expects it to be located at:

$HOME/oui.txt

2. Add the function to your ~/.zshrc

Open your shell config:

nano ~/.zshrc

Paste the following function at the bottom:

# whereyallfrom — uses local OUI file to look up vendors
# Download OUI file from: https://standards-oui.ieee.org/oui/oui.txt
# Save it as: $HOME/oui.txt

function whereyallfrom() {
  OUI_FILE="$HOME/oui.txt"

  if [[ ! -f "$OUI_FILE" ]]; then
    echo "Error: $OUI_FILE not found!"
    return 1
  fi

  clean_mac() {
    echo "$1" | tr -d ':-.' | tr '[:lower:]' '[:upper:]'
  }

  lookup_mac() {
    local mac="$1"
    local ip="$2"
    local cleaned=$(clean_mac "$mac")
    local oui=${cleaned:0:6}

    if [[ "$oui" == "FFFFFF" ]]; then
      echo "$ip | $mac | <broadcast>"
      return
    fi

    vendor=$(grep -i "^$oui" "$OUI_FILE" | grep "(base 16)" | awk -F'\t' '{print $2}' | sed 's/^ *//;s/ *$//' | head -n 1)

    if [[ -z "$vendor" ]]; then
      echo "$ip | $mac | No vendor found"
    else
      echo "$ip | $mac | $vendor"
    fi
  }

  printf "%-16s | %-17s | %-30s\n" "IP Address" "MAC Address" "Vendor"
  printf "%-16s-+-%-17s-+-%-30s\n" "----------------" "-----------------" "------------------------------"

  if [ $# -eq 0 ]; then
    arp -a | awk '/at/ {print $2, $4}' | sed 's/[()]//g' | while read -r ip mac; do
      lookup_mac "$mac" "$ip"
    done
  else
    for mac in "$@"; do
      lookup_mac "$mac" "-"
    done
  fi
}

To save and exit Nano:

  • Press Control + X
  • Press Y to confirm
  • Press Enter to save and close

3. Reload your shell

source ~/.zshrc

🧪 Usage

# Scan your local network and show vendors
whereyallfrom

# Look up specific MAC addresses (any format)
whereyallfrom 00:1A:2B:3C:4D:5E ee-cd-e0-7f-61-9e 001a.2b3c.4d5e

✅ Example Output

IP Address       | MAC Address       | Vendor
-----------------+------------------+------------------------------
192.168.1.12     | 60:3e:5f:66:7e:3a | Apple, Inc.
192.168.1.10     | 92:51:2a:36:d2:49 | Samsung Electronics
-                | 00:1A:2B:3C:4D:5E | CISCO SYSTEMS, INC.

💡 Notes

  • Requires oui.txt to be downloaded from IEEE and placed in $HOME
  • Matches MACs based on the first 6 hex digits (OUI)
  • Works without internet access

Made with ❤️ by Remote BB
For the nosy network nerd in all of us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment