How can I get the ESSID name only that I connected with?

Solution 1:

I don't know if this is the best solution, but try this:

For the essid name:

iwconfig wlan0 2> /dev/null | awk -F\" '{print $2}'

For the access point mode (as requested in the comment):

iwconfig wlan0 2> /dev/null | awk -F: '/Mode:/ {print $2}' | awk '{print $1}'

For the link Quality (as requested in the comment):

iwconfig wlan0 2> /dev/null | awk -F= '/Quality/ {print $2}' | awk '{print $1}'

For the channel, (as requested in the comment) try this:

sudo iwlist wlan0 scanning essid ESSID | grep Channel | head -1 | awk -F: '{print $2}'

Make sure to replace ESSID with your essid:

For the address, (as requested in the comment) try this:

ifconfig wlan0 2> /dev/null | awk -F: '/inet\ addr/ {print $2}' | awk '{print $1}'

Solution 2:

After toying around with tons of different commands, flags, greps, trims, awks, and seds, I finally settled on:

iwgetid -r

Simple and clean. This will output the SSID and nothing more. Previously, I was using this clunker:

iwconfig <iface> | grep ESSID | awk -F: '{print $2}' | sed 's/\"//g'

One of my favorite things about the *nix world is the ability to string together a bunch of commands and programs that utilize standard input and output to achieve whatever it is that I need. However, when a single flag can be passed to a program like iwgetid to accomplish the same thing, it's no longer a decision between which to use. It's an IQ test.

Keep in mind you can still specify different wireless network interfaces using iwgetid like so:

iwgetid <iface> -r