12345678910111213141516171819202122232425262728293031323334 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace ShareWifi.Utils.Net
- {
- class WifiUtils
- {
- /// <summary>
- /// 获取WIFI SSID ,如果为空则没有连接wifi
- /// </summary>
- /// <returns></returns>
- public static string getSSID()
- {
- string cmdRes = Shell.RunCmd("netsh wlan show interfaces | findstr SSID");
- Regex regex = new Regex("[^B]SSID\\s+:\\s(.*)");
- return regex.Match(cmdRes).Groups[1].Value.Trim();
- }
- /// <summary>
- /// 根据 SSID 获取密码
- /// </summary>
- /// <param name="ssid">SSID</param>
- /// <returns></returns>
- public static string getSSDIPassword(string ssid)
- {
- string cmdRes = Shell.RunCmd("netsh wlan show profile name=" + ssid + " key=clear | findstr Key");
- Regex regex = new Regex("Key Content\\s+:\\s(.*)");
- return regex.Match(cmdRes).Groups[1].Value.Trim();
- }
- }
- }
|