1

我的设置:Windows 7、Ruby 1.9.3

我想管理无线网卡以访问不同的无线路由器,这是我尝试过的:

方法一:netsh wlan

netsh通过命令工具管理 WLAN 适配器。

所以我在 Windows 中设置了我的无线网络并使用

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

哪个有效,然后我可以添加配置文件并通过执行以下操作进行连接:

> netsh wlan add profile ^
filename="d:\wireless-wuhongliang.xml" ^
interface="wireless" Profile

wuhongliang is added on interface Wireless.

> netsh wlan connect name="wuhongliang" ^
ssid="wuhongliang"
Connection request was completed successfully.

哪个可以使用导出的配置文件将我连接到 WLAN。

因此,查看 XML 配置文件:

<?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>

keyMaterial显然是加密的网络密码。因此,如果我更改路由器密码,那么配置文件就会中断,因为我没有新的 encrypted keyMaterial

因为我不知道如何生成keyMaterial这对我不起作用。

方法二:使用wlanapi.dll

在 codeproject.com 上找到了这篇文章,看起来很有希望。但我没有 C#、C、C++ 方面的经验。

我尝试使用dllwith Ruby DLWin32API但我不知道如何设置参数或使用这些库。

这是我用来调用 API 的 Ruby 代码WlanEnumInterfaces(但我很确定它不正确):

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*")
4

1 回答 1

1

sharedKey标签中将protected值更改为,false然后keyMaterial可以将值导入plaintext.

<sharedKey>
    <keyType>passPhrase</keyType>
    <protected>false</protected>
    <keyMaterial>[The Password]</keyMaterial>
  </sharedKey>

key=clear选项应该为您执行此操作,但显然不是。

于 2015-06-19T22:44:45.263 回答