How to get LAN IP of a client using .net c#

Get computer IP address - LAN and Internet using C#

using System.Net;
using System.IO;
/// <summary>
/// Get computer LAN address like 192.168.25.236
/// </summary>
/// <returns></returns>
private string GetComputerLanIP()
{
    string strHostName = System.Net.Dns.GetHostName();
 
    IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
     
    foreach (IPAddress ipAddress in ipEntry.AddressList)
    {
        if (ipAddress.AddressFamily.ToString() == "InterNetwork")
        {
            return ipAddress.ToString();
        }
    }
 
    return "-";
}

Get your INTERNET IP address

/// <summary>
/// Get computer INTERNET address like 122.102.127.130
/// </summary>
/// <returns></returns>
private string GetComputer_InternetIP()
{
    // check IP using DynDNS's service
    WebRequest request = WebRequest.Create("http://checkip.dyndns.org");
    WebResponse response = request.GetResponse();
    StreamReader stream = new StreamReader(response.GetResponseStream());
 
    // IMPORTANT: set Proxy to null, to drastically INCREASE the speed of request
    request.Proxy = null;
 
    // read complete response
    string ipAddress = stream.ReadToEnd();
 
    // replace everything and keep only IP
    return ipAddress.
        Replace("<html><head><title>Current IP Check</title></head><body>Current IP Address: ", string.Empty).
        Replace("</body></html>", string.Empty);
}
How to get LAN IP of a client using .net c# How to get LAN IP of a client using .net c# Reviewed by Bhaumik Patel on 8:32 PM Rating: 5