Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.