Created
January 16, 2020 09:11
-
-
Save karthikcru/bf455b60d65e6a81ae8478e4d01f4868 to your computer and use it in GitHub Desktop.
Get all MAC addresses in default network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#getting the default interface and ping the broadcast address to get all network IPs | |
if [ "$(uname)" == "Darwin" ]; then | |
interface=$(route -n get default | grep 'interface:' | grep -o '[^ ]*$') | |
broadcast=$(ifconfig | grep -A 2 $interface | tail -n 1 | cut -d\ -f6) | |
ping -c 4 -W 2000 $broadcast | |
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then | |
interface=$(route | grep '^default' | grep -o '[^ ]*$') | |
broadcast=$(/sbin/ifconfig $interface | grep 'inet addr' | cut -d: -f3 | awk '{print $1}') | |
ping -c 4 -W 2 -b $broadcast | |
fi | |
arp -a | cut -d\ -f4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment