mac の ssid のパスワードをターミナルからコマンド経由で取り出す。
security コマンドを使うと、無線LANのパスワード(PSK)を平分で取得することができる。
WiFiのキーをSSIDごとに、キーチェインが保存しているので、それを指定して取り出す感じ
コマンド
security find-generic-password -D "AirPort network password" -a $SSID -g
自分のキーチェインから取り出すのsudo はときに使わない、KeychainAgentからローカルのユーザー認証を聞かれるので自分のMacユーザー名とパスワードをいれる。
パスワードだけがほしい。
パスワードだけがほしいときは、 -w オプションにする
security find-generic-password -D "AirPort network password" -a $SSID -w
実行例
takuya@Desktop$ security find-generic-password -D "AirPort network password" -a 0000docomo -g
keychain: "/Library/Keychains/System.keychain"
version: 256
class: "genp"
attributes:
0x00000007 <blob>="0000docomo"
0x00000008 <blob>=<NULL>
"acct"<blob>="0000docomo"
"cdat"<timedate>=0x32303134303532353039333232305A00 "20140525093220Z\000"
"crtr"<uint32>=<NULL>
"cusi"<sint32>=<NULL>
"desc"<blob>="AirPort network password"
"gena"<blob>=<NULL>
"icmt"<blob>=<NULL>
"invi"<sint32>=<NULL>
"mdat"<timedate>=0x32303134303532353039333232305A00 "20140525093220Z\000"
"nega"<sint32>=<NULL>
"prot"<blob>=<NULL>
"scrp"<sint32>=<NULL>
"svce"<blob>="AirPort"
"type"<uint32>=<NULL>
password: "B35D084737"
ちなみに 0000docomo は日本全体で共通なので公開しても構わないものである。
実はオプションはほとんどなくてもいい。
明示的にSSIDを指定してわかりやすくして上記例を書いたけど。オプションは次のもので十分
sudo security find-generic-password -a 0000docomo -w
これで十分。
2018-07-18 追記
オプションについて記述を追加
参考資料
https://apple.stackexchange.com/questions/176119/how-to-access-the-wi-fi-password-through-terminal