Last active
November 1, 2024 09:01
-
-
Save wtakuo/7aa2218dcad851c995f7ae672602735e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 node | |
| // wpa_passphrase - Generate a WPA PSK from an ASCII passphrase for a SSID | |
| // usage: wpa_passphrase <ssid> [passphrase] | |
| const crypto = require('crypto'); | |
| if (process.argv.length < 3 || process.argv.length > 4) { | |
| console.error('usage: wpa_passphrase <ssid> [passphrase]'); | |
| process.exit(1); | |
| } | |
| const ssid = process.argv[2]; | |
| if (process.argv.length == 4) { | |
| psk(ssid, process.argv[3]); | |
| } | |
| else { | |
| const readline = require('readline'); | |
| const rl = readline.createInterface({ | |
| input: process.stdin, | |
| output: process.stdout | |
| }); | |
| rl.question("passphrase: ", function(passphrase) { | |
| console.log(''); | |
| psk(ssid, passphrase); | |
| rl.close(); | |
| }); | |
| rl._writeToOutput = function _writeToOutput(c) { | |
| // rl.output.write("*"); | |
| }; | |
| } | |
| function psk(ssid, passphrase) { | |
| const psk = crypto.pbkdf2Sync(passphrase, ssid, 4096, 32, 'sha1') | |
| .toString('hex'); | |
| console.log(`network={\n\tssid="${ssid}"\n\tpsk=${psk}\n}`); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment