friedrith / node-wifi

📶 NodeJS tool to manage wifi (connections, scans)
MIT License
396 stars 160 forks source link

Error when connect to Wi-Fi AP on mac mini #98

Open AltekJimmyChang opened 4 years ago

AltekJimmyChang commented 4 years ago

Can not connect to Wi-Fi AP with the connect API

Expected Behavior

With init({iface:null}), and then call connect function. it should find the interface automatical and connect to Wi-Fi AP

Current Behavior

It alwayse use the en0 to as Wi-Fi interface. But it may en1 in some model

Affected features

Possible Solution

Use the networksetup -listallhardwareports can find the proper interface. Below is my code.

function osx_initWiFi(callback) { let args = ['-listallhardwareports']; execFile('networksetup', args, { env }, function(err, resp) { let respList = resp.split('\n'); let wifiIndex=respList.findIndex( item=> item==="Hardware Port: Wi-Fi"); if (wifiIndex!==-1) { let wifiStr = respList[wifiIndex+1].split(':'); let out = wifiStr[1].trim(); console.log(got wifi port :${out} , ${out.length}); callback && callback(out); }else { callback && callback(null); } }); }

osx_initWiFi(ret=>init({iface:ret}))

Steps to Reproduce (for bugs)

      1. 4.

Context

Your Environment