This commit is contained in:
@@ -21,6 +21,47 @@ info() {
|
||||
echo "[*] $*"
|
||||
}
|
||||
|
||||
# Return 0 if interface is physical (non-virtual)
|
||||
is_physical_iface() {
|
||||
local iface="$1"
|
||||
local dev_path
|
||||
dev_path=$(readlink -f "/sys/class/net/${iface}/device" 2>/dev/null || true)
|
||||
[[ -n "$dev_path" && "$dev_path" != *"/virtual/"* ]]
|
||||
}
|
||||
|
||||
# Resolve bridge/bond to the underlying physical NIC, if possible
|
||||
resolve_physical_iface() {
|
||||
local iface="$1"
|
||||
local candidate resolved
|
||||
|
||||
# If iface is a bridge, iterate its members
|
||||
if [[ -d "/sys/class/net/${iface}/bridge" ]]; then
|
||||
for brif in /sys/class/net/${iface}/brif/*; do
|
||||
[[ -e "$brif" ]] || continue
|
||||
candidate=$(basename "$brif")
|
||||
resolved=$(resolve_physical_iface "$candidate")
|
||||
[[ -n "$resolved" ]] && echo "$resolved" && return
|
||||
done
|
||||
fi
|
||||
|
||||
# If iface is a bond, walk its slaves
|
||||
if [[ -f "/sys/class/net/${iface}/bonding/slaves" ]]; then
|
||||
for slave in $(<"/sys/class/net/${iface}/bonding/slaves"); do
|
||||
resolved=$(resolve_physical_iface "$slave")
|
||||
[[ -n "$resolved" ]] && echo "$resolved" && return
|
||||
done
|
||||
fi
|
||||
|
||||
# If iface itself is physical, return it
|
||||
if is_physical_iface "$iface"; then
|
||||
echo "$iface"
|
||||
return
|
||||
fi
|
||||
|
||||
# Fallback: return original iface even if virtual
|
||||
echo "$iface"
|
||||
}
|
||||
|
||||
# --- Preconditions -----------------------------------------------------------
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
@@ -66,6 +107,14 @@ fi
|
||||
|
||||
info "Detected primary interface: ${PRIMARY_IF}"
|
||||
|
||||
PHYSICAL_IF=$(resolve_physical_iface "$PRIMARY_IF")
|
||||
if [[ "$PHYSICAL_IF" != "$PRIMARY_IF" ]]; then
|
||||
info "Resolved underlying physical interface: ${PHYSICAL_IF}"
|
||||
PRIMARY_IF="$PHYSICAL_IF"
|
||||
else
|
||||
info "Using ${PRIMARY_IF} as the primary physical interface."
|
||||
fi
|
||||
|
||||
# --- Get MAC address & IP ----------------------------------------------------
|
||||
|
||||
MAC_ADDR=$(ip -o link show "$PRIMARY_IF" | awk '{for (i=1; i<=NF; i++) if ($i=="link/ether") print $(i+1)}')
|
||||
|
||||
Reference in New Issue
Block a user