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}') |