How to get my local computer IP in C#

1 Answer

0 votes
using System;
using System.Net;
using System.Net.Sockets;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            IPHostEntry host;
            host = Dns.GetHostEntry(Dns.GetHostName());
            foreach (IPAddress IP in host.AddressList)
            {
                if (IP.AddressFamily == AddressFamily.InterNetwork)
                {
                    Console.WriteLine(IP.ToString());
                    break;
                }
            }
        }
    }
}


answered Apr 8, 2014 by avibootz

Related questions

1 answer 291 views
1 answer 222 views
1 answer 378 views
1 answer 364 views
1 answer 247 views
1 answer 245 views
...