You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varwifi=require('node-wifi');// Initialize wifi module// Absolutely necessary even to set interface to nullwifi.init({iface : null// network interface, choose a random wifi interface if set to null});// Scan networkswifi.scan(function(err,networks){if(err){console.log(err);}else{console.log(networks);/* networks = [ { ssid: '...', bssid: '...', mac: '...', // equals to bssid (for retrocompatibility) channel: <number>, frequency: <number>, // in MHz signal_level: <number>, // in dB security: 'WPA WPA2' // format depending on locale for open networks in Windows security_flags: '...' // encryption protocols (format currently depending of the OS) mode: '...' // network mode like Infra (format currently depending of the OS) }, ... ]; */}});// Connect to a networkwifi.connect({ssid : "10086",password : "123456"},function(err){if(err){console.log(err);}console.log('Connected');});
创建配置文件
导出已有配置文件,会显示你曾经输入过的WIFI密码的配置文件
name和SSID可以不同(最好设为一致)
connectionMode可以为手动连接的manual或者自动连接的auto;
keyMaterial处填写密码,无密码状态如下:
检查配置文件是否已经存在:
删除配置文件:
添加配置文件:
netsh wlan add profile filename="WLAN-10086.xml"
注意这里面参数是文件名,默认路径为当前目录,添加成功后提示:已将配置文件 10086 添加到接口 WLAN
可以在命令行运行一下命令扫描WiFi信息:
进行连接:
重要的事情说三遍:这里的name是刚刚添加过的配置文件中的name,而不是配置文件名!
连接成功的提示信息为已成功完成连接请求。
配合Node
我们可以使用Node编写JS去实现连接,读取配置文件并连接
常用netsh命令总结:
netsh wlan show profile
netsh wlan export profile key=clear
netsh wlan delete profile name=""
netsh wlan add profile filename=""
netsh wlan connect name=""
netsh wlan show interface
netsh interface set interface "Interface Name" enabled
netsh wlan show networks mode=bssid
node-wifi
参考文档
The text was updated successfully, but these errors were encountered: