zoukankan      html  css  js  c++  java
  • 获取wifi密码

    wifi的SSID获取资料较多,但wifi密码的获取资料较少,获取的主要思路是通过 profile文件

    随笔写了一个供参考:

    private static string Password(string sSID)
            {
                string netshProfile = $"wlan show profile name = {sSID}";
                string netshProfilePassword = $"wlan show profile name = {sSID} key = clear";
                string profile = NetshProcess(netshProfile);
                string profilePassword = NetshProcess(netshProfilePassword);
    
                var profileArray = FilterProfile(profile);
                var profilePasswordArray = FilterProfile(profilePassword);
    
                string password = string.Empty;
    
                int yeirdIndex = Math.Min(profilePasswordArray.Count, profileArray.Count);
                for (int i = 0; i < yeirdIndex; i++)
                {
                    if (profilePasswordArray[i] == profileArray[i]) continue;
                    password = profilePasswordArray[i].Split(new char[] { '', ':' })[1];
                    break;
                }
                return password;
            }
    
            private static List<string> FilterProfile(string profile)
            {
                var profileArray = profile.Split(new char[] { '\r', '\n' }).Reverse().ToList();
                for (int i = profileArray.Count - 1; i >= 0; i--)
                {
                    if (string.IsNullOrWhiteSpace(profileArray[i])|| !profileArray[i].Contains(":") && !profileArray[i].Contains(""))
                        profileArray.RemoveAt(i);
                }
                return profileArray;
            }
    
            public static string NetshProcess(string args)
            {
                using (var p = new Process())
                {
                    p.StartInfo = new ProcessStartInfo("netsh", args);
    
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.StartInfo.CreateNoWindow = true;
                    p.Start();
                    string output = p.StandardOutput.ReadToEnd();
                    p.WaitForExit();
                    return output;
                }
            }
    View Code
  • 相关阅读:
    windows下面安装Python和pip教程
    Python已安装第三方库
    Python安装cx_Oracle第三方库(Mac osx Yosemite Intel i5环境)
    7.Python进阶_函数对象
    6.Python进阶_循环对象
    5.Python进阶_循环设计
    UltraEdit中粘贴问题
    UltraEdit的代码片的编码设置
    使用C#实现SSLSocket加密通讯 Https
    sql while 循环要加begin end
  • 原文地址:https://www.cnblogs.com/terryK/p/15589155.html
Copyright © 2011-2022 走看看