Last active
May 17, 2024 18:09
-
-
Save hivehand/2a4e2305b23d3bd10cabe63ff75a9b2d to your computer and use it in GitHub Desktop.
Scriptlet for creating QR codes that let people join a WiFi network just by scanning the code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
# Take a network SSID as an argument, and prompt for the corresponding | |
# password. Generate a WiFi-network credential set suitable for QR | |
# encoding as defined in: | |
# | |
# https://github.com/zxing/zxing/wiki/Barcode-Contents#wi-fi-network-config-android-ios-11 | |
# | |
# then generate that QR code and save it to `<SSID>-QR.png`. | |
# | |
# It does all of this using Duncan Robertson's rqrcode Gem: | |
# | |
# https://github.com/whomwah/rqrcode | |
require 'rqrcode' | |
require 'io/console' | |
network = ARGV.first | |
if network | |
passwd = STDIN.getpass("Password: ") | |
wifi_info = "WIFI:S:#{network};T:WPA;P:#{passwd};;" | |
filename = "#{network}-QR.png" | |
RQRCode::QRCode.new(wifi_info). | |
as_png(size: 360, file: filename) | |
else | |
puts <<~EOM | |
Generate the PNG of a QR code for WiFi-network access. Pass it the | |
SSID (WiFi network name); it will prompt for the password and | |
generate `<SSID>-QR.png`. | |
EOM | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment