淺談利用Node.js如何取得WI-FI密碼
利用Node.js如何取得WI-FI密碼?以下這篇文章跟大家介紹一下使用Node.js取得WI-FI密碼的方法,希望對大家有幫助!
【推薦學習:《nodejs 教學》】
示範效果
全域安裝wifi-password-cli
依賴
npm install wifi-password-cli -g # or npx wifi-password-cli
使用
$ wifi-password [network-name] $ wifi-password 12345678 $ wifi-password 办公室wifi a1234b2345
覺得Node.js很神奇是麼?其實並不是,我們看看它是如何實現的
實作原理
#OSX系統
##透過下面的指令查詢wifi密碼security find-generic-password -D "AirPort network password" -wa "wifi-name"
Linux系統
所有的wi-fi連線資訊都在/etc/NetworkManager/system-connections/資料夾中
sudo cat /etc/NetworkManager/system-connections/<wifi-name>
Windows系統
透過下面的指令查詢wifi密碼netsh wlan show profile name=<wifi-name> key=clear
實作原始碼
它的實作原始碼也很簡單,有興趣可以學習https://github.com/kevva/wifi-password入口檔案是index.js,先透過判斷使用者的作業系統去選擇不同的取得方式
'use strict'; const wifiName = require('wifi-name'); module.exports = ssid => { let fn = require('./lib/linux'); if (process.platform === 'darwin') { fn = require('./lib/osx'); } if (process.platform === 'win32') { fn = require('./lib/win'); } if (ssid) { return fn(ssid); } return wifiName().then(fn); };
Linux'use strict';
const execa = require('execa');
module.exports = ssid => {
const cmd = 'sudo';
const args = ['cat', `/etc/NetworkManager/system-connections/${ssid}`];
return execa.stdout(cmd, args).then(stdout => {
let ret;
ret = /^\s*(?:psk|password)=(.+)\s*$/gm.exec(stdout);
ret = ret && ret.length ? ret[1] : null;
if (!ret) {
throw new Error('Could not get password');
}
return ret;
});
};
登入後複製
'use strict'; const execa = require('execa'); module.exports = ssid => { const cmd = 'sudo'; const args = ['cat', `/etc/NetworkManager/system-connections/${ssid}`]; return execa.stdout(cmd, args).then(stdout => { let ret; ret = /^\s*(?:psk|password)=(.+)\s*$/gm.exec(stdout); ret = ret && ret.length ? ret[1] : null; if (!ret) { throw new Error('Could not get password'); } return ret; }); };
OSX'use strict';
const execa = require('execa');
module.exports = ssid => {
const cmd = 'security';
const args = ['find-generic-password', '-D', 'AirPort network password', '-wa', ssid];
return execa(cmd, args)
.then(res => {
if (res.stderr) {
throw new Error(res.stderr);
}
if (!res.stdout) {
throw new Error('Could not get password');
}
return res.stdout;
})
.catch(err => {
if (/The specified item could not be found in the keychain/.test(err.message)) {
err.message = 'Your network doesn\'t have a password';
}
throw err;
});
};
登入後複製
'use strict'; const execa = require('execa'); module.exports = ssid => { const cmd = 'security'; const args = ['find-generic-password', '-D', 'AirPort network password', '-wa', ssid]; return execa(cmd, args) .then(res => { if (res.stderr) { throw new Error(res.stderr); } if (!res.stdout) { throw new Error('Could not get password'); } return res.stdout; }) .catch(err => { if (/The specified item could not be found in the keychain/.test(err.message)) { err.message = 'Your network doesn\'t have a password'; } throw err; }); };
Windows'use strict';
const execa = require('execa');
module.exports = ssid => {
const cmd = 'netsh';
const args = ['wlan', 'show', 'profile', `name=${ssid}`, 'key=clear'];
return execa.stdout(cmd, args).then(stdout => {
let ret;
ret = /^\s*Key Content\s*: (.+)\s*$/gm.exec(stdout);
ret = ret && ret.length ? ret[1] : null;
if (!ret) {
throw new Error('Could not get password');
}
return ret;
});
};
登入後複製更多程式相關知識,請造訪:
'use strict'; const execa = require('execa'); module.exports = ssid => { const cmd = 'netsh'; const args = ['wlan', 'show', 'profile', `name=${ssid}`, 'key=clear']; return execa.stdout(cmd, args).then(stdout => { let ret; ret = /^\s*Key Content\s*: (.+)\s*$/gm.exec(stdout); ret = ret && ret.length ? ret[1] : null; if (!ret) { throw new Error('Could not get password'); } return ret; }); };
程式設計影片! !
以上是淺談利用Node.js如何取得WI-FI密碼的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

基於無阻塞、事件驅動建立的Node服務,具有記憶體消耗低的優點,非常適合處理海量的網路請求。在海量請求的前提下,就需要考慮「記憶體控制」的相關問題了。 1. V8的垃圾回收機制與記憶體限制 Js由垃圾回收機

選擇一個Node的Docker映像看起來像是小事,但是映像的大小和潛在漏洞可能會對你的CI/CD流程和安全造成重大的影響。那我們要如何選擇一個最好Node.js Docker映像呢?

Node 19已正式發布,以下這篇文章就來帶大家詳解了解Node.js 19的 6 大特性,希望對大家有幫助!

文件模組是對底層文件操作的封裝,例如文件讀寫/打開關閉/刪除添加等等文件模組最大的特點就是所有的方法都提供的**同步**和**異步**兩個版本,具有sync 字尾的方法都是同步方法,沒有的都是異

事件循環是 Node.js 的基本組成部分,透過確保主執行緒不被阻塞來實現非同步編程,了解事件循環對建立高效應用程式至關重要。以下這篇文章就來帶大家深入了解Node中的事件循環 ,希望對大家有幫助!

如何用pkg打包nodejs可執行檔?以下這篇文章跟大家介紹一下使用pkg將Node專案打包為執行檔的方法,希望對大家有幫助!
