8

Is there a simple command to find out to which Wi-Fi AP I am connected?

I have several networks configured in my /etc/wpa_supplicant.d/wpa_supplicant.conf, with assigned priorities, and depending where I am I connect to the best available Wi-Fi/SSID. Connection happens automatically, so I don't know to which SSID I am connected.

Now I need to check (inside a script) whether I am connected at home, or somewhere else.

I know that I can list all available SSIDs with

iwlist wlan0 scan

But how can I print the SSID to which I am connected at the moment?

I am using Debian.

4 Answers 4

16

How about iwgetid? The iwgetid(8) man page says:

iwgetid is used to find out the NWID, ESSID or AP/Cell Address of the wireless network that is currently used.

2
  • 4
    iwgetid wlan0 --raw is exactly what I was looking for. Thanks. Commented Sep 27, 2014 at 22:38
  • From what I've seen so far, if the computer doesn't have Wi-Fi configured, iwgetid may not be installed, so that is something you may want to check first. And then if it is installed but not connected, iwgetid --raw will output nothing and exit with status code 255.
    – Fenhl
    Commented May 2, 2021 at 13:44
3

None of the programs recommended in the previous answers was already installed on my system. However, iw was. Therefore,

iw dev

does the trick. And if you really want just the ssid (e.g. for a script)

iw dev | grep ssid | awk '{print $2}'

works for me.

1
  • What system are you using, in what version?
    – Unix
    Commented Jun 15, 2020 at 19:47
2

This may work:

/sbin/iwconfig wlan0 | grep ESSID
0

Searching for a solution to this for a script. Found the answer from xel worked really way except for ssid's with space so modified slightly

iw dev | grep ssid | awk -F 'ssid ' '{print $2}'

possible an abuse of the awk command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .