Home
Manage Your Code
Snippet: Getting Local IP (C#)
Title: Getting Local IP Language: C#
Description: This method returns the Local IP Address of a machine, LAN IP if connected to LAN. Views: 402
Author: Fuad Ahmed Hasni Date Added: 6/14/2012
Copy Code  
1 public string LocalIPAddress()
2        {
3            IPHostEntry host;
4            string localIP = "";
5            host = Dns.GetHostEntry(Dns.GetHostName());
6            foreach (IPAddress ip in host.AddressList)
7            {
8                if (ip.AddressFamily == AddressFamily.InterNetwork)
9                {
10                    localIP = ip.ToString();
11                    break;
12                }
13            }
14            return localIP;
15        }
16