From 9b36b04b6cbc5f9b5cf24ea55ce58e5f172a0bf2 Mon Sep 17 00:00:00 2001 From: oitsjustjose Date: Tue, 9 Sep 2025 12:28:13 -0500 Subject: [PATCH] QR Code Generator for WiFi Network --- linux/python/.gitignore | 1 + linux/python/dep_mgr.py | 29 +++++++++++++++++++++++++++++ linux/python/wifi_qr.py | 23 +++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 linux/python/.gitignore create mode 100644 linux/python/dep_mgr.py create mode 100644 linux/python/wifi_qr.py diff --git a/linux/python/.gitignore b/linux/python/.gitignore new file mode 100644 index 0000000..ed8ebf5 --- /dev/null +++ b/linux/python/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/linux/python/dep_mgr.py b/linux/python/dep_mgr.py new file mode 100644 index 0000000..64b1458 --- /dev/null +++ b/linux/python/dep_mgr.py @@ -0,0 +1,29 @@ +# https://bootstrap.pypa.io/get-pip.py + +import os +import sys +import tempfile + +import requests + +PYTHON = sys.executable + + +def _prereq() -> None: + res = os.system(f"{PYTHON} -m pip") + if res == 0: + return + + data = requests.get("https://bootstrap.pypa.io/get-pip.py") + filename = tempfile.mktemp() + with open(filename, "w", encoding="utf-8") as fh: + fh.write(data.text) + + os.system(f"{PYTHON} {filename}") + os.unlink(filename) + + +def install_package(package_name: str) -> None: + _prereq() + os.system(f"{PYTHON} -m pip install {package_name}") + print(f"Package {package_name} has been installed - please rerun this command!") diff --git a/linux/python/wifi_qr.py b/linux/python/wifi_qr.py new file mode 100644 index 0000000..b8cbe34 --- /dev/null +++ b/linux/python/wifi_qr.py @@ -0,0 +1,23 @@ +import argparse +import dep_mgr + +try: + import qrcode +except ImportError: + dep_mgr.install_package("qrcode[pil]") +finally: + import qrcode + + +def main(args): + img = qrcode.make(f"WIFI:S:{args.ssid};T:WPA;P:{args.passwd};;") + img.save(args.output) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(prog="WiFi QR Generator", description="Creates QR Codes to join a Password Protected WiFi Network") + parser.add_argument("ssid", help="The SSID of the WiFi Network to connect to") + parser.add_argument("passwd", help="The passphrase of the WiFi Network to connect to") + parser.add_argument("-o", "--output", required=True, help="Where to save the resulting image to") + args = parser.parse_args() + main(args)