- [C#] Hướng dẫn viết ứng dụng theo dõi máy in bao nhiêu trang (Monitor Printer)
- [C#] Lấy thông tin cấu hình máy tính xuất ra text file winform
- [C#] Chia sẽ class Install, Uninstall, Start và Stop Services Winform
- [C#] Tìm kiếm tập tin file nhanh chóng trên Winform sử dụng thư viện FastSearchLibrary
- [C#] Giới thiệu thư viện Fluent FTP Awesome dùng để làm việc với FTP
- [C#] Sử dụng thư viện Mini Profiler Integrations ghi log thực hiện các câu lệnh SQL
- [DEVEXPRESS] Thiết kế Dropdown ButtonBarItem trên Form Ribbon
- [C#] Lưu trạng thái các control trên Winform vào Registry Windows
- [C#] Ứng dụng ví dụ Simple Observer Pattern tăng giảm số lượng trên winform
- [C#] Hướng dẫn lấy thời gian thực server time trên winform
- [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 lấy tất cả các ip cùng lớp mạng trong mạng LAN
Xin chào các bạn, hôm nay mình sẽ tiếp tục hướng dẫn các bạn cách lấy tất cả các tên máy và ipadrress trong mạng LAN bằng ngôn ngữ lập trình C#.
[C#] GET ALL IPADDRESS IN LAN NETWORK
Cách tìm kiếm chúng ta sẽ sử dụng hàm "NET VIEW" trong MS-DOS, để lấy thông tin tất cả các máy.
Sau đó, chúng ta sẽ cắt chuỗi từ hàm NET VIEW trả về và hiển thị dữ liệu lên ListView.
Bước 1: Các bạn mở màn hình CMD và gõ vào lệnh NET VIEW để xem kết quả như hình bên dưới:
- Theo hình trên, các bạn sẽ thấy được dữ liệu trả về gồm 3 máy.
Bước 2: Cắt chuỗi dữ liệu trả về và hiển thị nó lên Listview.
Giao diện phần mềm lấy tất cả ipaddress trong mạng nội bộ
Full source code get ip in Lan C#:
private void button1_Click(object sender, EventArgs e)
{
Process netUtility = new Process();
netUtility.StartInfo.FileName = "net.exe";
netUtility.StartInfo.CreateNoWindow = true;
netUtility.StartInfo.Arguments = "view";
netUtility.StartInfo.RedirectStandardOutput = true;
netUtility.StartInfo.UseShellExecute = false;
netUtility.StartInfo.RedirectStandardError = true;
netUtility.Start();
StreamReader streamReader = new StreamReader(netUtility.StandardOutput.BaseStream, netUtility.StandardOutput.CurrentEncoding);
string line = "";
while ((line = streamReader.ReadLine()) != null)
{
if (line.StartsWith("\"))
{
string pcname = line.Substring(2).Substring(0, line.Substring(2).IndexOf(" ")).ToUpper();
string myIP = Convert.ToString(Dns.GetHostByName(line.Substring(2).Substring(0, line.Substring(2).IndexOf(" ")).ToUpper()).AddressList[0].ToString());
ListViewItem item = new ListViewItem(new string[] { pcname, myIP }, 0);
listView1.Items.AddRange(new ListViewItem[] { item });
}
}
streamReader.Close();
netUtility.WaitForExit(1000);
}
HAPPY CODING