獲取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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM