[clug] How to Determine which Wireless Lan is connected

Alex (Maxious) Sadleir maxious at gmail.com
Tue Sep 29 05:04:27 MDT 2009


On Tue, Sep 29, 2009 at 8:47 PM, Jeff <smee.heee at gmail.com> wrote:
> Essentially I am trying to determine which ESSID I am connected to.
>
> Example:
> ESSID 1 - BettyWLan
> ESSID 2 - BarneyWLan
>
> if connected to BettyWLan do
>  BettyWLan something
> elsif BarneyWLan do
>  BarneyWLan something
> else
>  Something else
> fi
>
> I am fine, at the moment, with the selection statement, but can not find a reliable and simple way to determine what Wireless LAN I am connected to.

As root, you can easily see this in the output of the iwconfig/iwgetid
command. These commands aren't accessable as a normal user usually but
you can make a user group and give it extra priviledges to the
/sbin/iw* files for that if you need to.

In either case, you can use the iwconfig output in a shell script like
below (shell scripting wizards may object to my speedy hack novice use
of sed ;-)

ESSID=`iwconfig wlan0| grep 'ESSID' | sed 's/.*ESSID://' | sed 's/"//g'`
if [ $ESSID = "BarneyWLan" ]; then
  echo "Hello Barney"
fi


More information about the linux mailing list