WifiUtils.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7. namespace ShareWifi.Utils.Net
  8. {
  9. class WifiUtils
  10. {
  11. /// <summary>
  12. /// 获取WIFI SSID ,如果为空则没有连接wifi
  13. /// </summary>
  14. /// <returns></returns>
  15. public static string getSSID()
  16. {
  17. string cmdRes = Shell.RunCmd("netsh wlan show interfaces | findstr SSID");
  18. Regex regex = new Regex("[^B]SSID\\s+:\\s(.*)");
  19. return regex.Match(cmdRes).Groups[1].Value.Trim();
  20. }
  21. /// <summary>
  22. /// 根据 SSID 获取密码
  23. /// </summary>
  24. /// <param name="ssid">SSID</param>
  25. /// <returns></returns>
  26. public static string getSSDIPassword(string ssid)
  27. {
  28. string cmdRes = Shell.RunCmd("netsh wlan show profile name=" + ssid + " key=clear | findstr Key");
  29. Regex regex = new Regex("Key Content\\s+:\\s(.*)");
  30. return regex.Match(cmdRes).Groups[1].Value.Trim();
  31. }
  32. }
  33. }