7

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.

3 Answers 3

15

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. 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
    May 2, 2021 at 13:44
2

This may work:

/sbin/iwconfig wlan0 | grep ESSID
1

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
    Jun 15, 2020 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.