WhichWiFI — A small Python script I wrote for macOS to display the currently connected Wi-Fi.

Shashank Srivastava
2 min readJan 28, 2021

This small Python script, in just 10 lines (including comments), notifies me of the Wi-Fi my Mac is connected to by displaying a notification.

There are times when you have more than 1 Wi-Fi router and they differ in their speed/tariff or data-limit. Sometimes you want to connect to a router that has a cheaper or unlimited data plan. Sometimes you want to minimize your usage of a specific router because it has a data cap & also incurs a lot of money if that cap is crossed. Sometimes you want to connect to a different router because you need fast speed. Situations may vary.

The problem arises when your Mac silently switches to another router if the connected router runs out of battery or gets switched off. You won’t even notice & might end up receiving a huge bill or exhausting your daily limit quite fast (Any Indian reader can attest to this).

Mac also tries to connect to other networks if certain settings (remember this network or auto-connect) are enabled for those networks.

Also, you don’t want to shop online & enter your net banking password or card details when your Mac is connected to a free Wi-Fi hotspot in a coffee shop. Free hotspots are not secure.

WhichWiFi checks the network your Mac is connected to & displays it as a notification. You can put it inside a Cron job so that you continue to receive notifications about the currently connected network without any human intervention.

Requirements

  • Python 3
  • pync module for Python 3
  • macOS

I’ve tested it on macOS Mojave 10.14.6

Steps to perform

  • Copy the below Python script.
  • Install the pync module for Python 3.
admin@shashank-mbp ~> pip3 install pync
  • Test the script.
admin@shashank-mbp ~/D/WhichWiFi> python3.4 WhichWiFi.py
You are connected to : Airtel-WD670-EA3C

You should see an output similar to the above & also a notification like this.

I hope you liked the post. It may be a trivial thing, but provides a piece of valuable information when it matters. I’ve been a victim of being connected to the wrong hotspot, which exhausted all the available data :-)

--

--

Shashank Srivastava

DevSecOps Architect @Virtualness. Music/Book/Photography/Fitness lover & Blogger.