3

I'm looking for a way to identify the WiFi network to which my Raspberry Pi is connected in my program (Python) so that I can use the name of the WiFi.

3 Answers 3

4

From the command line

iwgetid

will give you the ssid of the active wlan. More config information can also be seen with

iwconfig

You can parse this data and use it in your program to display wlan info.

1
  • See also iw link (e.g., iw wlan0 link).
    – goldilocks
    Jun 9, 2017 at 17:46
1

You can use the iproute2 command iw to get to which your rpi is connected:

iw dev <interface> link | grep SSID | awk '{print $2}'
0

iwconfig may help (man page: https://linux.die.net/man/8/iwconfig). When called with an interface name iwconfig wlan0 it should print the current information, which also includes the ESSID -- the network name.

You may need to "sanitize" the network name when you plan to use it as a hostname: hostnames should be conforming to DNS label rules, and only consist of letters, digits, and hyphens, with some additional constraints applied (so-called LDH rule). In particular, you need to remove blanks, dots, underscores, and many ASCII characters.

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.