Monday, November 15, 2010

Finding Local IP Address in C#.NET

This snippet of code helps you find the local PC's IP Address from the Host Name. Be aware that it uses the IPv6 address if available.



 System.Net.IPHostEntry h =
            System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
            string IPAddress = h.AddressList.GetValue(0).ToString();
            string lm = System.Net.Dns.GetHostName().ToString();

No comments:

Post a Comment