Get the App
SLTechnology News&Howtos  ›  Development  › 

How to get WI-FI password using Node.js

Shulou Source: shulou.com Published: 2022-06-03 17:24:50 11月13日 Update

This article is about how to use Node.js to get WI-FI passwords. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Demonstration effect

Global installation of wifi-password-cli dependency

Npm install wifi-password-cli-g # ornpx wifi-password-cli

Use

$wifi-password [network-name] $wifi-password12345678 $wifi-password Office wifia1234b2345

Think Node.js is amazing, huh? Actually, it's not. Let's see how it works.

Implementation principle OSX system

Query the wifi password with the following command

Security find-generic-password-D "AirPort network password"-wa "wifi-name" Linux system

All wi-fi connection information is in the / etc/NetworkManager/system-connections/ folder

We query the wifi password with the following command

Sudo cat / etc/NetworkManager/system-connections/Windows system

Query the wifi password with the following command

Netsh wlan show profile name= key=clear implementation source code

Its implementation source code is also very simple, you can learn if you are interested.

Https://github.com/kevva/wifi-password

The entry file is index.js. First of all, choose a different acquisition method by judging the user's operating system.

'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;});}; OSX'use strict';const execa = require (' execa'); module.exports = ssid = > {const cmd = 'security' Const args = ['find-generic-password','-dating, '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\ stdout: (. +)\ s*$/gm.exec (stdout); ret = ret & & ret.length? Ret [1]: null; if (! ret) {throw new Error ('Could not get password');} return ret;});}; Thank you for reading! This is the end of the article on "how to get the WI-FI password using Node.js". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Password system command face-to-face query content file more source code article different good practical magical operating system information entry global interest office Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia macOS Shulou Tech Info MariaDB MySQL