Beispiel #1
0
        public static bool GetWifiState(ref NetshInfo ni)
        {
            const string cmd    = "netsh wlan show hostednetwork";
            string       result = ExecuteDOS(cmd);

            string[]     res     = result.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            var          ht      = new Hashtable();
            const string pattern = @"^([a-fA-F\d]{2})(([/\s:-][a-fA-F\d]{2}){5})";
            var          lstMac  = new List <string>();

            for (int i = 0; i < res.Length; i++)
            {
                string line  = res[i];
                Match  match = Regex.Match(line.Trim(), pattern);
                if (match.Success)
                {
                    lstMac.Add(match.ToString());
                }
                else
                {
                    string[] ls = line.Split(new[] { ':', ':' }, 2, StringSplitOptions.RemoveEmptyEntries);
                    if (ls.Length == 2)
                    {
                        if (!ht.ContainsKey(ls[0].Trim()))
                        {
                            ht.Add(ls[0].Trim(), ls[1].Trim(new[] { '“', '”', '\r', '\n', ' ' }));
                        }
                    }
                }
            }
            GetNetshInfo(ht, ni);
            ni.MAC = lstMac;
            return(CheckHashtable(ht, "模式", "已启用") && CheckHashtable(ht, "状态", "已启动"));
        }
Beispiel #2
0
        private void GetWifiState()
        {
            NetshInfo ni = new NetshInfo();

            wifiState = CMD.GetWifiState(ref ni);
            if (!ni.IsEmpty)
            {
                txtSSID.Text = ni.SSID;
                txtKey.Text  = ni.KEY;
            }
        }
Beispiel #3
0
 private static void GetNetshInfo(Hashtable ht, NetshInfo ni)
 {
     ni.SSID = GetHashString(ht, "SSID 名称");
     if (!ni.IsEmpty)
     {
         ni.BSSID          = GetHashString(ht, "BSSID");
         ni.Channel        = GetHashString(ht, "频道");
         ni.ClientCount    = GetHashInt32(ht, "客户端数");
         ni.IdentityAuth   = GetHashString(ht, "身份验证");
         ni.MaxClientCount = GetHashInt32(ht, "最多客户端数");
         ni.Password       = GetHashString(ht, "密码");
         ni.WiFiType       = GetHashString(ht, "无线电类型");
         GetWifiKey(ref ht, ref ni);
     }
     ni.HashTable = ht;
 }
Beispiel #4
0
        private void btnShowClient_Click(object sender, EventArgs e)
        {
            NetshInfo ni = new NetshInfo();

            wifiState = CMD.GetWifiState(ref ni);
            string text = string.Format("客户端数:{0}", ni.ClientCount);

            text += Environment.NewLine;
            text += "序号\tMAC";
            text += Environment.NewLine;
            text += "---------------------------------";
            for (int i = 0; i < ni.MAC.Count; i++)
            {
                text += string.Format("{2}{0}\t{1}", i + 1, ni.MAC[i], Environment.NewLine);
            }

            MessageBox.Show(text, @"当前连接客户端");
        }
Beispiel #5
0
        private static void GetWifiKey(ref Hashtable ht, ref NetshInfo ni)
        {
            const string cmdkey = "netsh wlan show hostednetwork security";
            string       rekey  = ExecuteDOS(cmdkey);

            string[] res = rekey.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string line in res)
            {
                string[] ls = line.Split(new[] { ':', ':' }, 2, StringSplitOptions.RemoveEmptyEntries);
                if (ls.Length == 2)
                {
                    if (!ht.ContainsKey(ls[0].Trim()))
                    {
                        ht.Add(ls[0].Trim(), ls[1].Trim(new[] { '“', '”', '\r', '\n', ' ' }));
                    }
                }
            }
            ni.KeyUsage  = GetHashString(ht, "用户安全密钥用法");
            ni.SystemKey = GetHashString(ht, "系统安全密钥");
            ni.KEY       = GetHashString(ht, "用户安全密钥");
        }