Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get WI-FI password using Node.js

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report