#!/bin/sh
# Universal MAC Address Grabber for Linux & BSD
# Compatible with POSIX sh (bash, zsh, dash, ksh)
# Helper function to clean up and print in a uniform format
print_mac() {
# Takes "interface mac" and prints if MAC looks valid (matches 6 hex pairs)
if echo "$2" | grep -iqE '^([0-9a-f]{2}[:-]){5}[0-9a-f]{2}$'; then
printf "%-15s %s\n" "$1" "$2"
fi
}
echo "Detected Network Interfaces & MAC Addresses:"
echo "-------------------------------------------"
# 1. Try sysfs method (Linux system, reliable, no binary dependencies)
if [ -d /sys/class/net ]; then
for iface in /sys/class/net/*; do
ifname=$(basename "$iface")
# Skip loopback
if [ "$ifname" != "lo" ] && [ -f "$iface/address" ]; then
mac=$(cat "$iface/address")
print_mac "$ifname:" "$mac"
fi
done
exit 0
fi
# 2. Try 'ip' command (Modern Linux / iproute2)
if command -v ip >/dev/null 2>&1; then
ip -o link show | awk '$2 != "lo:" {print $2, $(NF-2)}' | tr -d ':' | while read -r dev mac; do
# Extract interface name properly (strip trailing colon or @vlan)
clean_dev=$(echo "$dev" | cut -d: -f1 | cut -d@ -f1)
# Fetch actual link/ether MAC
actual_mac=$(ip link show "$clean_dev" 2>/dev/null | awk '/link\/ether/ {print $2}')
print_mac "$clean_dev:" "$actual_mac"
done
exit 0
fi
# 3. Try 'ifconfig' method (BSD / macOS / Legacy Linux / SLES minimal)
if command -v ifconfig >/dev/null 2>&1; then
# ifconfig format varies between BSD and Linux
ifconfig -a | awk '
/^[a-zA-Z0-9_-]+/ {
iface=$1
sub(":", "", iface)
}
# BSD / macOS / Solaris syntax (ether / address)
/ether|hwaddr|address/ {
for (i=1; i<=NF; i++) {
if ($i ~ /^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$/) {
if (iface != "lo" && iface != "lo0") {
print iface ":", $i
}
}
}
}
' | while read -r dev mac; do
print_mac "$dev" "$mac"
done
exit 0
fi
echo "Error: Could not determine network interfaces (missing sysfs, ip, and ifconfig)." >&2
exit 1
| # | Change | User | Description | Committed | |
|---|---|---|---|---|---|
| #1 | 33409 | Claude (AI Agent by Anthropic) |
Copy Up from //p4-sdp/dev_rebrand into //p4-sdp/dev. This is the first promotion of dev_rebrand's work into dev since dev_rebrand was created (2025-05-24) -- 303 files, covering the entire 2026.1 rebranding effort (SDP-1379), the Secure By Default adaptation (SDP-1350), OrgName-aware auth.id/ServerID (SDP-1286), RCS-keyword version identification (SDP-1161/SDP-799), and the Streams-native release process redesign (Task 5) done this session, plus everything else accumulated in dev_rebrand's history before this session. Per the Merge Down/Copy Up flow, this is intentionally a full, unconditional blast-replace of dev's content from dev_rebrand -- all selectivity/care happened in the preceding Merge Down (dev -> dev_rebrand, changes 33407-33408), which absorbed Robert Cowham's independent dev-side work first so nothing of his is lost by this Copy Up. Two files are worth calling out since they might look alarming in isolation: - tools/mdcu.sh is deleted -- intentional, retired this session in favor of the two direct Streams commands now documented in doc/ReleaseProcessOverview.md. - tools/ReleaseProcessOverview.md is deleted -- this is a stale relic of a file move dev_rebrand made back in 2025-05-24 (tools/ -> doc/) that was never previously propagated to dev; the current, fully-rewritten doc/ReleaseProcessOverview.md is added/updated correctly by this same changelist. |
||
| //p4-sdp/dev_rebrand/Server/Unix/setup/get_mac_addresses.sh | |||||
| #1 | 33189 | C. Thomas Tyler | Added utility to get MAC address, useful for generating MAC-based license files. | ||