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 196 views
1 answer 117 views
1 answer 248 views
1 answer 275 views
1 answer 165 views
1 answer 152 views
...