Getting Local IP Address

2:05 AM
public static  string GetLocalIP()
        {
            string _IP = null;

            System.Net.IPHostEntry _IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());

            foreach (System.Net.IPAddress _IPAddress in _IPHostEntry.AddressList)
            {
                if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
                {
                    _IP = _IPAddress.ToString();
                }
            } 
            return _IP;
        }

0 comments:

Post a Comment