- [DEVEXPRESS] Hướng dẫn bật tính năng Scroll Pixcel in Touch trên GridView
- [DEVEXPRESS] Hướng dẫn sử dụng TileBar viết ứng dụng duyệt hình ảnh Winform
- [DEVEXPRESS] Tô màu border TextEdit trên Winform
- [C#] Lấy dữ liệu từ Console Write hiển thị lên textbox Winform
- [C#] Hiển thị Progress bar trên Window Console
- [C#] Di chuyển control Runtime và lưu layout trên winform
- [SQLSERVER] Sử dụng hàm NULL IF
- [C#] Chia sẽ source code mã đi tuần bằng giao diện Winform
- [C#] Flash Window in Taskbar Winform
- Download và Giải nén tập tin File sử dụng Powershell
- [C#] Hướng dẫn cách lấy thông tin đăng nhập tài khoản và mật khẩu web browser trên windows
- [VB.NET] CRUD Thêm xóa sửa tìm kiếm Realtime FireBase
- [C#] Hiển thị thông báo Toast Message trong lập trình Winform
- [C#] Cấu hình định dạng ngày tháng, thời gian trên Windows cho ứng dụng Winform
- [C#] Rút gọn đường dẫn link url với TinyURL API
- [C#] Hướng dẫn cách bo tròn winform with Radius
- [C#] Chia sẽ class BackGroundOverlay Show Modal cho Winform
- [C#] Hướng dẫn Flip Image Winform
- [C#] Invoke là gì? cách sử dụng phương thức Invoke()
- [C#] Hướng dẫn chia sẽ file, folder từ ứng dụng sang Zalo Chat
[C#] Hướng dẫn xem mật khẩu wifi đã lưu trữ trong máy tính
Bài viết hôm nay, mình sẽ hướng dẫn các bạn cách xem mật khẩu Wifi trong lập trình C#. Thông thường, khi các bạn kết nối với một wifi và chọn nhớ mật khẩu, thì hệ thống sẽ lưu trữ thông tin của một profile wifi đó.
+ Cách thực hiện viết ứng dụng xem wifi, đầu tiên mình sẽ hướng dẫn các bạn xem mật khẩu bằng CMD (MS-DOS), và từ câu lệnh command này mình sẽ lấy dữ liệu output xuất ra và hiển thị chúng lên phần mềm.
1. Đầu tiên, các bạn mở MS-DOS Command và chạy với quyền Run as Administrator.
Thực hiện lệnh đọc các wifi của windows đã lưu trữ.
Gõ lệnh: netsh wlan show profile
=> Kết quả trả về như hình bên dưới:
- Ở hình ảnh, trên đã hiển thị cho chúng ta thấy danh sách tất cả các profile.
Và bây giờ nếu mình muốn xem mật khẩu của wifi "Agribank" mình thực hiện lệnh sau:
netsh wlan show profile agribank key=clear
Và dưới đây là hình ảnh mật khẩu của Wifi Agribank:
- Và bây giờ mình sẽ lập trình ứng dụng, các bạn chỉ cần tạo vòng for duyệt qua các profile của wifi để lấy thông tin và hiển thị lên DataGridView là xong.
Giao diện ứng dụng:
Source code show profile wifi C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.IO;
namespace WifiPass
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int count = 0;
int count_names = 0;
DataTable table = new DataTable();
#region console functions
private string wifilist()
{
Process processWifi = new Process();
processWifi.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
processWifi.StartInfo.FileName = "netsh";
processWifi.StartInfo.Arguments = "wlan show profile";
processWifi.StartInfo.UseShellExecute = false;
processWifi.StartInfo.RedirectStandardError = true;
processWifi.StartInfo.RedirectStandardInput = true;
processWifi.StartInfo.RedirectStandardOutput = true;
processWifi.StartInfo.CreateNoWindow = true;
processWifi.Start();
string output = processWifi.StandardOutput.ReadToEnd();
string err = processWifi.StandardError.ReadToEnd();
processWifi.WaitForExit();
return output;
}
private string wifipassword(string wifiname)
{
string argument = "wlan show profile name="" + wifiname + "" key=clear";
Process processWifi = new Process();
processWifi.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
processWifi.StartInfo.FileName = "netsh";
processWifi.StartInfo.Arguments = argument;
processWifi.StartInfo.UseShellExecute = false;
processWifi.StartInfo.RedirectStandardError = true;
processWifi.StartInfo.RedirectStandardInput = true;
processWifi.StartInfo.RedirectStandardOutput = true;
processWifi.StartInfo.CreateNoWindow = true;
processWifi.Start();
string output = processWifi.StandardOutput.ReadToEnd();
string err = processWifi.StandardError.ReadToEnd();
processWifi.WaitForExit();
return output;
}
private string wifipassword_single(string wifiname)
{
string get_password = wifipassword(wifiname);
using (StringReader reader = new StringReader(get_password))
{
string line;
while ((line = reader.ReadLine()) != null)
{
Regex regex2 = new Regex(@"Key Content * : (?.*)");
Match match2 = regex2.Match(line);
if (match2.Success)
{
string current_password = match2.Groups["after"].Value;
return current_password;
}
}
}
return "Open Network";
}
#endregion
#region process data for wifi names
private void parse_lines(string input)
{
using (StringReader reader = new StringReader(input))
{
string line;
while ((line = reader.ReadLine()) != null)
{
count++;
regex_lines(line);
}
}
}
private void command_dump(string input_raw)
{
textBox1_pass.Text += input_raw + "
";
}
#endregion
#region regex
private void regex_lines(string input2)
{
Regex regex1 = new Regex(@"All User Profile * : (?.*)");
Match match1 = regex1.Match(input2);
if (match1.Success)
{
count_names++;
string current_name = match1.Groups["after"].Value;
string password = wifipassword_single(current_name);
table.Rows.Add(count_names, current_name, password);
textBox1_pass.Text += string.Format("{0}{1}{2}", count_names.ToString().PadRight(7), current_name.PadRight(20), password) + "
";
}
}
#endregion
#region table
private void init_table()
{
table.Columns.Add("Number", typeof(int));
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Password", typeof(string));
}
private void reset_all()
{
count = 0;
count_names = 0;
table.Rows.Clear();
textBox1_pass.Text = "";
}
#endregion
private void get_passwords()
{
string wifidata = wifilist();
parse_lines(wifidata);
}
private void colorOpenWifi()
{
int rowscount = dataGridView1.Rows.Count;
for (int i = 0; i < rowscount; i++)
{
if (Convert.ToString(dataGridView1.Rows[i].Cells[2].Value).StartsWith("Open Network") == true)
{
dataGridView1.Rows[i].Cells[2].Style.BackColor = Color.LawnGreen;
}
if (Convert.ToString(dataGridView1.Rows[i].Cells[2].Value).Length < 9)
{
dataGridView1.Rows[i].Cells[2].Style.BackColor = Color.Yellow;
}
}
dataGridView1.Refresh();
}
private void export_CSV()
{
DateTime theDate = DateTime.Now;
string dateString = theDate.ToString("dd-MM-yy-HH.mm.ss");
string filename = "wifiPass-" + dateString + ".csv";
var lines = new List();
string[] columnNames = table.Columns.Cast().
Select(column => column.ColumnName).
ToArray();
var header = string.Join(",", columnNames);
lines.Add(header);
var valueLines = table.AsEnumerable()
.Select(row => string.Join(",", row.ItemArray));
lines.AddRange(valueLines);
File.WriteAllLines(filename, lines);
}
private void Form1_Load(object sender, EventArgs e)
{
init_table();
}
private void button_getPasswords_Click(object sender, EventArgs e)
{
button_getPasswords.Enabled = false;
button2_exportCSV.Enabled = false;
reset_all();
get_passwords();
dataGridView1.DataSource = table;
colorOpenWifi();
button_getPasswords.Enabled = true;
button2_exportCSV.Enabled = true;
}
private void button2_exportCSV_Click(object sender, EventArgs e)
{
button_getPasswords.Enabled = false;
button2_exportCSV.Enabled = false;
reset_all();
get_passwords();
dataGridView1.DataSource = table;
colorOpenWifi();
export_CSV();
button_getPasswords.Enabled = true;
button2_exportCSV.Enabled = true;
MessageBox.Show("CSV Exported", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
HAPPY CODING