Lấy IP mạng LAN với C#

Lấy IP mạng LAN với C#

Cách code lấy IP mạng LAN với C# 

public  string GetLocalIPAddress()
    {
        var host = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
        foreach (var ip in host.AddressList)
        {
            if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                return ip.ToString();
            }
        }
        throw new Exception("No network adapters with an IPv4 address in the system!");
    }

 String ip= GetLocalIPAddress();

Nếu IP mạng Lan của máy tính bạn là 192.1.1.33 thì biến ip nhận giá trị 192.1.1.33

Lấy IP mạng LAN với C#