- Get link
- X
- Other Apps
Here is a usefull block of code to retrieve a host IPAddress: private static class Network { #region DNS public static IPAddress FindIPAddress( bool localPreference) { return FindIPAddress( Dns .GetHostEntry( Dns .GetHostName()), localPreference); } public static IPAddress FindIPAddress( IPHostEntry host, bool localPreference) { if (host == null ) throw new ArgumentNullException ( "host" ); if (host.AddressList.Length == 1) return host.AddressList[0]; else { foreach (System.Net. IPAddress address in host.AddressList) { bool local = IsLocal(address); if (local && localPreference) return address; ...