Skip to content

Instantly share code, notes, and snippets.

@Gronis
Last active June 20, 2020 18:30
Show Gist options
  • Save Gronis/dc2c58223fe1ca53541b88bcca0241a4 to your computer and use it in GitHub Desktop.
Save Gronis/dc2c58223fe1ca53541b88bcca0241a4 to your computer and use it in GitHub Desktop.
Get the mac address for a certain host.
#!/bin/bash
#
# Get the mac address for a certain host.
#
# Requires ping and arp tool.
#
# Usage:
# get_mac_address HOSTNAME
#
HOST=$1
PATTERN='[0-9a-fA-F]*:[0-9a-fA-F]*:[0-9a-fA-F]*:[0-9a-fA-F]*:[0-9a-fA-F]*:[0-9a-fA-F]*'
ping -c 1 $HOST > /dev/null && arp -n $HOST | grep -io $PATTERN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment