Last active
July 15, 2024 02:23
-
-
Save wtakuo/a003179bd997aeb574a1bb7dbd611d05 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 python3 | |
| # wpa_passphrase - Generate a WPA PSK from an ASCII passphrase for a SSID | |
| # usage: wpa_passphrase <ssid> [passphrase] | |
| import sys | |
| from hashlib import pbkdf2_hmac | |
| from getpass import getpass | |
| if len(sys.argv) < 2 or len(sys.argv) > 3: | |
| print("usage: wpa_passphrase <ssid> [passphrase]", file = sys.stderr) | |
| sys.exit(1) | |
| ssid = sys.argv[1].encode('utf-8') | |
| if len(sys.argv) == 2: | |
| passphrase = getpass('passphrase: ').encode('utf-8') | |
| else: | |
| passphrase = sys.argv[2].encode('utf-8') | |
| psk = pbkdf2_hmac('sha1', passphrase, ssid, 4096, 32).hex() | |
| print(f'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