How to use “Native Wifi API” Windows API functions with ruby -


my setup: windows 7, ruby 1.9.3

i want manage wireless nic access different wireless routers, here's have tried:

method 1: netsh wlan

managing wlan adapter through netsh command tools.

so setup wireless network in windows , exported using

netsh wlan export profile name="wuhongliang" folder = "d:\" interface="wireless" key=clear 

which worked, can add profile , connect doing:

> netsh wlan add profile ^ filename="d:\wireless-wuhongliang.xml" ^ interface="wireless" profile  wuhongliang added on interface wireless.  > netsh wlan connect name="wuhongliang" ^ ssid="wuhongliang" connection request completed successfully. 

which works , connects me wlan using exported profile.

so looking @ xml profile:

<?xml version="1.0" ?> <wlanprofile xmlns="http://www.microsoft.com/networking/wlan/profile/v1">   <name>wuhongliang</name>   <ssidconfig>     <ssid>       <hex>7775686f6e676c69616e67</hex>       <name>wuhongliang</name>     </ssid>   </ssidconfig>   <connectiontype>ess</connectiontype>   <connectionmode>auto</connectionmode>   <msm>     <security>       <authencryption>         <authentication>wpa2psk</authentication>         <encryption>aes</encryption>         <useonex>false</useonex>       </authencryption>       <sharedkey>         <keytype>passphrase</keytype>         <protected>true</protected>         <keymaterial>[long encrypted key]</keymaterial>       </sharedkey>     </security>   </msm> </wlanprofile> 

the keymaterial encrypted network password. if change router password profile breaks because don't have new encrypted keymaterial.

since don't know how generate keymaterial won't work me.

method 2: using wlanapi.dll

i found this article on codeproject.com , looked promising. have no experience in c#,c,c++.

i tried using dll ruby dl , win32api don't how set parameters or use libraries in general.

this ruby code used call wlanenuminterfaces api (but i'm pretty sure it's incorrect):

c_handle = 1 c_reserved = 0 c_interfacelist=" "*10000  dllname = "wlanapi.dll"  pro=win32api.new(dllname, "wlanenuminterfaces", ['p', 'l', 'p'], "v")  p pro.call(handle, c_reserved, c_interfacelist)  p c_interfacelist.unpack("l*") 

in sharedkey tag change protected value false , keymaterial value can imported in plaintext.

<sharedkey>     <keytype>passphrase</keytype>     <protected>false</protected>     <keymaterial>[the password]</keymaterial>   </sharedkey> 

the key=clear option supposed you, wasn't.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -