21 lines
591 B
Bash
Executable File
21 lines
591 B
Bash
Executable File
function get_client_mac_address() {
|
|
# Usage: get_client_mac_address <interface_name>
|
|
local ETH_IFACE="$1"
|
|
local TARGET_IP="192.168.2.2"
|
|
|
|
# Check if the interface is plugged in
|
|
if ip link show "$ETH_IFACE" | grep -q "state UP"; then
|
|
local MAC_ADDRESS=$(arp -i "$ETH_IFACE" -n | grep "$TARGET_IP" | awk '{print $3}')
|
|
|
|
if [ -n "$MAC_ADDRESS" ]; then
|
|
echo "$MAC_ADDRESS"
|
|
else
|
|
echo "Could not find the MAC address of the connected device with IP address $TARGET_IP"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "Interface $ETH_IFACE is not plugged in."
|
|
exit 1
|
|
fi
|
|
}
|