Skip to content

Instantly share code, notes, and snippets.

View karthikcru's full-sized avatar

Karthik Natarajan karthikcru

View GitHub Profile
@karthikcru
karthikcru / find_all_macs.sh
Created January 16, 2020 09:11
Get all MAC addresses in default network
#!/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}')