#二维码 #Wi-Fi #编码 #访问 #生成 #凭证 #编码

bin+lib wifiqr

生成 Wi-Fi 访问二维码

5 个版本

0.0.8 2022年7月9日
0.0.7 2021年2月17日
0.0.6 2020年3月29日
0.0.5 2020年1月21日
0.0.4 2019年12月31日

#415 in 认证

MIT 许可证

330KB
784

WifiQr

这个 Rust crate 将 Wi-Fi 凭证编码到二维码中。也提供命令行界面用于测试和基本使用。

版本

要使用 WifiQr 的命令行实现,请从 版本标签下载预构建的二进制文件。

工具使用

USAGE:
    wifiqr [ --ssid (ssid) ] [ --password (password) | --ask ]
            [ --encr encryption type (default:wpa2) ]
            [ --imagefile (output_name.png) | --svg | --svgfile (output_name.svg) ]

FLAGS:
        --hidden      Optional: Indicate whether or not the SSID is hidden
        --svg         Emit the QR code as an SVG (to standard output)
        --console     Print the QR code out to the console
    -d, --debug       Display some extra debugging output
    -a, --ask         Ask for password instead of getting it through the command-line
        --ask-echo    Ask for password while displaying input on the console
        --quote       If the SSID or password could be mistaken for a hexadecimal value, 
                                          this option will add double-quotes around the SSID and password
    -h, --help        Prints help information
    -V, --version     Prints version information

OPTIONS:
        --ssid <ssid>               Sets the WiFi SSID
        --password <password>       Sets the WiFi password [default: ]
        --encr <encryption>         The WiFi's encryption type (wpa, wpa2, nopass) [default: wpa2]
        --scale <scale>             QR code scaling factor [default: 10]
        --quietzone <quiet_zone>    QR code: The size of the quiet zone/border to apply to the final QR code [default:
                                    2]
        --imagefile <image_file>    The name of the file to save to (e.g. --imagefile qr.png). Formats: [png, jpg, bmp]
        --svgfile <svg_file>        Save the QR code to a file (SVG formatted)

此包可在 crates.io 上找到。请确保将您使用的版本固定到特定版本(或提交),以避免任何可能破坏您应用程序的更改(将尽力确保这不是问题所在)。

extern crate wifiqr;

fn main() {
    let quiet_zone = 5;
    let config = wifiqr::code::auth(
        Some("ssid"),       // Network name (ssid)
        Some("password"),   // Network password/passphrase
        Some("wpa2"),       // WPA | WPA2 | WEP
        false,              // Hidden SSID (true | false)
        false,              // SSID needs to be quoted (true | false)
    );

    let encoding = wifiqr::code::encode(&config).expect("There was a problem generating the QR code");

    // this passes the svg output from the QR encoder back
    println!("{}", wifiqr::code::make_svg(&encoding));

    // this prints a qr code to the console
    wifiqr::code::console_qr(&encoding, quiet_zone);
}

构建

GitHub 上提供了预构建版本,但为了开发或从源代码构建(在安装Rust 工具链之后)

cargo build --release

关于在 Wi-Fi 认证中使用的二维码信息

使用的包

依赖项

~11MB
~165K SLoC