Skip to content

Instantly share code, notes, and snippets.

@akpoff
Created April 18, 2016 16:10
Show Gist options
  • Save akpoff/0a1bd5bab81d78a0863747ba55f0065b to your computer and use it in GitHub Desktop.
Save akpoff/0a1bd5bab81d78a0863747ba55f0065b to your computer and use it in GitHub Desktop.
Get the nwid of the specified wlan card or the first found
#!/bin/sh
nic="$1"
function getNwid {
ifconfig $1 | grep ieee80211 | cut -d : -f 2 | rev | cut -d ' ' -f 5- | rev | cut -d ' ' -f 3- | tr -d '"'
}
if [ ${nic:-empty} = empty ]
then
wnics_up=$(ifconfig wlan | grep UP | cut -d ':' -f 1)
if [ ${wnics_up:-empty} = empty ]
then
wnics=$(ifconfig wlan | cut -d ':' -f 1)
for wnic in $wnics
do
echo $wnic: Not connected
exit
done
else
for wnic in $wnics_up
do
nwid=$(getNwid $wnic)
echo $wnic: $nwid
exit
done
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment