#!/bin/sh function arp { printf "$(cat /proc/net/arp)" } gateway_ip="$(ip route | grep default | awk '{print $3}')" ping -c 1 "$gateway_ip" -W 1 &> /dev/null gateway_mac="$(arp | grep -w "$gateway_ip" | awk '{print $4}')" echo "$gateway_mac"