Quote:
Originally Posted by drumbum
I want autodetect my wireless interface and send "wlan0" to $interface and use it through out the whole script. I know it would probably be easier just reading a "what is your interface" | read interface but id really like to try and autodetect.
I have tried iwconfig > iw.txt to generate a text file with my wireless interface, but Im having trouble getting the information from it, I either get the whole file when I use interface$=(cat /root/iw.txt) or sometimes nothing at all, I really just want to read the first word which is wlan0 and send that to $interface
I dont something similar with the mac address
mac=$(/sbin/ifconfig $interface | awk '/HWaddr/{print $NF}) but Im not getting the same result when Im applying it too iwconfig???
|
I'm not sure I understand what you want
1. to get the name of your wireless card interface, you can
run this
grep ':' /proc/net/wireless |head -n1|cut -d':' -f1
then it should display
wlan0
or whatever
so if you want to store that into a variable, you do
interface=$(grep ':' /proc/net/wireless |head -n1|cut -d':' -f1)
2. if you need to know the essid you're connected to
you run this (as root)
iwgetid $interface
and it should display something like:
wlan0 ESSID:"some essid"
if you need to store that info into an essid variable you do:
essid="$(iwgetid $interface | sed 's?^.*ESSID:.\(.*\).$?\1?')"
3. if you need the mac address
mac=$(ifconfig $interface | grep HWaddr|sed 's?^.*HWaddr ??')