I will explain it precisely!
We have each others mac address.Now to check either any of my friend is online or not i execute the following command:
sudo ifconfig en0 ether xx:xx:xx:xx:xx:xx; sudo ifconfig en0 down; sudo ifconfig en0 ether up; sleep 6; ping -c 3 www.google.co.in;
Where xx:xx:xx:xx:xx:xx=MAC ADDRESS, en0=ethernet
I use sleep as it takes about 6 seconds to connect router
So ping shows me result whether they are online or not
Now i have 8 such mac addresses in a txt file organised as each in one line.
Q1) Can i use only one command such that it takes each mac address from text file one by one and uses it in above command and ends as my txt ends?
Q2) Is there any Alternative command for above purpose as the above command is organised by myself to work properly as per my use?
I work with Mac OS
Here's the final quote
#!/bin/bash
while read m; do
echo Checking MAC address: $m
sudo ifconfig en0 ether $m
sudo ifconfig en0 down
sudo ifconfig en0 up
sleep 5
i=1
while [ $i -eq 1 ]
do
ping -c 3 www.google.co.in > /dev/null
e=$?
if [ $e -eq 0 ]
then
echo ONLINE
i=0
echo $m >> ONLINE.txt
elif [ $e -eq 2 ]
then
echo OFFLINE
i=0
echo $m >> OFFLINE.txt
else
echo Waiting To be Connected
i=1
sleep 4
fi
done
done < macs.txt
echo HI, These macs are ONLINE
cat ONLINE.txt
echo Sorry these are OFFLINE
cat OFFLINE.txt
rm ONLINE.txt OFFLINE.txt
Thanks for helping guys!