Answers for "get ip from url c#"

C#
12

how to get ip address in c#

public static string GetLocalIPAddress()
{
    var host = Dns.GetHostEntry(Dns.GetHostName());
    foreach (var ip in host.AddressList)
    {
        if (ip.AddressFamily == AddressFamily.InterNetwork)
        {
            return ip.ToString();
        }
    }
    throw new Exception("No network adapters with an IPv4 address in the system!");
}
Posted by: Guest on June-25-2020
-1

get sites ip in C#

var url = "https://www.google.com/";
Uri myUri = new Uri(url);
var ip = Dns.GetHostAddresses(myUri.Host)[0];
Posted by: Guest on September-04-2020

C# Answers by Framework

Browse Popular Code Answers by Language