Recently made a Mac gadget WiFiPassword, can view the Mac current connection WiFi password. Check out the GitHub link for more information on the project.

Specifically, WiFiPassword solves the following problems:

  1. When you forget your Mac WiFi password, you can use it to check your WiFi password
  2. When the Mac has been connected to WiFi, it can generate a TWO-DIMENSIONAL code for the phone to scan the code and automatically join the current WiFi
  3. You can save WiFi information as a picture

Running UI screenshots

interface screenshots
The UI main interface
Saved WiFi information picture

Software information

The software information of WiFiPassword is as follows:

  1. Development language: Swift 5
  2. UI: SwiftUI
  3. Operating environment: Mac 10.15+

The principle is introduced

First look at how to check the WiFi password from the keystring. Here’s how:

How to use the program to get the corresponding WiFi name and password?

The idea comes from the open source project wifi-Password, which is a Python project. You can view the wifi password in Mac, Linux and Windows.

On Mac, you can view the current WiFi information by shell command:

// Step 1: Judge the path for "/ System/Library/PrivateFrameworks/Apple80211 framework/Versions/Current/Resources/airport" if the file exists / / step 2: Gets the Current Mac are using WiFi name/System/Library/PrivateFrameworks/Apple80211 framework/Versions/Current/Resources/airport - I | Awk '/ SSID / {{print substr ($0, index ($0, $2)}}' / / step 3: Obtain the corresponding password from the keystring. Security find-generic-password -l "replaces the WiFi name" -d 'AirPort network password' -w obtained in Step 2Copy the code

Awk ‘/ SSID/ {{print substr($0, index($0, $2))}} awk ‘/ SSID/ {{print substr($0, index($0, $2))}} AWK is a powerful text analysis tool. For details, see the AWK command.

WiFiPassword is also obtained by executing the shell command above.

Qr code

When you get the name and password of WiFi, how to generate a QR code for the phone to scan the code to automatically log in?

The WiFi name (SSID) and password into a fixed format string:

static func getQRCodeText(ssid: String.password: String) -> String {
    return "WIFI:T:WPA; S:\(ssid); P:\(password);"
}
Copy the code

WPA (English: Wi-Fi Protected Access), which means “Wi-Fi Access Protection”, is a technical standard to protect wireless network Access security. zh.wikipedia.org/wiki/WPA

other

In addition, WiFiPassword borrows from other projects:

  1. The UI showing WiFi information refers to the wifi-Card project;
  2. The code that generates two-dimensional code is adapted to Mac on the basis of QRCode.

Finally, check out the GitHub link for project information.