private static string QueryCurrentDevices(bool wait = false) { try { var status = WlanManager.QueryStatus(); if (status.HostedNetworkState != WlanHostedNetworkState.Active) { return("查询客户端失败,托管网络尚未启用。"); } var result = new StringBuilder(); var lookup = Lookup; var i = 0; foreach (var peer in status.PeerList) { i++; result.AppendFormat("设备 #{0} {1}", i, GetDeviceDetails(peer, wait, lookup, string.Empty.PadLeft(8 + (int)Math.Floor(Math.Log10(i))))); } return(result.ToString()); } catch (Exception exc) { return("查询客户端失败,详细信息:" + exc.GetMessage()); } }
private static void ShowStatus() { Try(() => { WlanOpcodeValueType opCode; try { WlanHostedNetworkConnectionSettings cs; opCode = WlanManager.QueryConnectionSettings(out cs); Console.WriteLine("托管网络连接设置来源:\t{0}\nSSID:\t\t\t{1}\n最大客户端数:\t\t{2}", WlanManager.ToString(opCode), cs.HostedNetworkSSID.Content, cs.MaxNumberOfPeers); } catch (BadConfigurationException) { } WlanHostedNetworkSecuritySettings ss; opCode = WlanManager.QuerySecuritySettings(out ss); Console.WriteLine("托管网络安全设置来源:\t{0}\n验证算法:\t\t{1}\n加密算法:\t\t{2}", WlanManager.ToString(opCode), WlanManager.ToString(ss.Dot11AuthAlgo), WlanManager.ToString(ss.Dot11CipherAlgo)); try { string profile; opCode = WlanManager.QueryStationProfile(out profile); Console.Write("托管网络配置文件来源:\t{0}\n配置文件:\n{1}", WlanManager.ToString(opCode), profile.Trim('\0')); } catch (BadConfigurationException) { } bool enabled; opCode = WlanManager.QueryEnabled(out enabled); Console.WriteLine("托管网络启用设置来源:\t{0}\n托管网络启用:\t\t{1}", WlanManager.ToString(opCode), enabled ? '是' : '否'); string passKey; bool isPassPhrase, isPersistent; var reason = WlanManager.QuerySecondaryKey(out passKey, out isPassPhrase, out isPersistent); if (reason == WlanHostedNetworkReason.Success) { Console.WriteLine("密码:\t\t\t{0}\n使用密码短语:\t\t{1}\n永久密码:\t\t{2}", passKey, isPassPhrase ? '是' : '否', isPersistent ? '是' : '否'); } else { Console.WriteLine("查询密码失败,原因:" + WlanManager.ToString(reason)); } var status = WlanManager.QueryStatus(); Console.WriteLine("状态:\t\t\t" + WlanManager.ToString(status.HostedNetworkState)); if (status.HostedNetworkState == WlanHostedNetworkState.Unavailable) { return; } Console.WriteLine("实际网络 ID:\t\t{0}\nBSSID:\t\t\t{1}", status.IPDeviceID, status.wlanHostedNetworkBSSID); if (status.HostedNetworkState == WlanHostedNetworkState.Active) { Console.WriteLine("802.11 物理层类型:\t{0}\n网络接口信道频率:\t{1}\n已认证客户端数量:\t{2}", WlanManager.ToString(status.dot11PhyType), status.ulChannelFrequency, status.dwNumberOfPeers); } }); }