WiFiQRCode - Generate Wi-Fi Network Config QR Code

example-qrcode-image

Introduction

最近在翻閱 ZXing 文件時,意外發現行動裝置可以掃描透過 QR Code 來加入 Wi-Fi。因此本篇就利用這個概念,透過 .NET Core 來實作一個可以以命令列產生 Wi-Fi Network Config QR Code 的 Console Application。

註:此方法目前僅適用於 Android, iOS 11+。

WiFiQRCode

A command-line tool of generating Wi-Fi network config to QR code, which is based on .NET Core 2.1 ,ImageSharp and ZXing.Net.

Scanning QR Code to configure the device’s Wi-Fi only support Android and iOS 11+.

Environment Requires

Verify that after successful installation of .NET Core Runtime:

1
$ dotnet --version

File Structure

1
2
3
4
5
6
7
8
─┬─ Microsoft.Win32.SystemEvents.dll.dll
├─ SixLabors.Core.dll
├─ SixLabors.ImageSharp.dll
├─ System.Drawing.Common.dll
├─ System.Runtime.CompilerServices.Unsafe.dll
├─ WiFiQRCode.dll
├─ WiFiQRCode.runtimeconfig.json
└─ zxing.dll

Parameters Description

Parameter Desciption Options Default Value Required
-a,
–auth_type
Wi-Fi authentication. WEP/WPA/WPA2/nopass WPA2 yes
-s,
—ssid
Wi-Fi SSID. yes
-p,
—password
Wi-Fi password.
-h,
—hidden
Wi-Fi is hidden or not.
-m,
—mode
Generate mode. display/image/both image
-it,
—image_type
The output image type, when mode is image/both. bmp/gif/jpeg/jpg/png png
-iw,
—image_width
The output image width, when mode is image/both. value >= 41 200
-ih,
—image_height
The output image height, when mode is image/both. value >= 41 200
-od,
—output_dir
The output directory, when mode is image/both. Current directory

Usage

Terminal Image
example-qrcode-terminal.png example-qrcode-image

Display Wi-Fi QR Code on Terminal

1
$ dotnet WiFiQRCode.dll --auth_type=WPA2 --ssid=example-qrcode --password=example-pass --mode=display

Output Wi-Fi QR Code to BMP file

1
$ dotnet WiFiQRCode.dll --auth_type=WPA2 --ssid=example-qrcode --password=example-pass --mode=image --image_type=bmp

Output Wi-Fi QR Code to BMP file in parent directory

1
$ dotnet WiFiQRCode.dll --auth_type=WPA2--ssid=example-qrcode --password=example-pass --mode=image --image_type=bmp --output_dir=../

Run application and enter each value

1
2
3
4
5
6
7
8
9
10
11
$ dotnet WiFiQRCode.dll
Wi-Fi Authentication Type :
Wi-Fi SSID :
Wi-Fi Password :
Generate Mode :

# If generate mode is image/both
Image Type :
Image Width :
Image Height :
Output Directory :

References