Skip to content

Instantly share code, notes, and snippets.

@jptalusan
Created August 2, 2019 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jptalusan/e9cabc1c7dc7675c5690492634bc62bc to your computer and use it in GitHub Desktop.
Save jptalusan/e9cabc1c7dc7675c5690492634bc62bc to your computer and use it in GitHub Desktop.
For pinging things connected to the ethernet at port eno1 of the device you are using.
#!/bin/bash
declare -A devices
devices["name"]="MAC_address"
for i in "${!devices[@]}"
do
#echo "key: $i"
#echo "value: ${devices[$i]}"
arp=$(sudo arp-scan --interface=eno1 --local | grep ${devices[$i]})
arp_arr=( $arp )
if [ "$i" = "nuc1" ]; then
ip=$(/sbin/ifconfig eno1 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
echo "${ip} $i"
else
echo "${arp_arr[0]} $i"
fi
done
for i in "${!devices[@]}"
do
arp=$(sudo arp-scan --interface=eno1 --local | grep ${devices[$i]})
arp_arr=( $arp )
#echo "$i ${devices[$i]} ${arp_arr[0]}"
if [ "$i" = "nuc1" ]; then
ip=$(/sbin/ifconfig eno1 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
echo "$i ${devices[$i]} ${ip}"
else
echo "$i ${devices[$i]} ${arp_arr[0]}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment