Monitor/TaskTrayForm.cs
/// <summary>
/// Get the local IPv4 address of the same segment as the default gateway.
/// </summary>
/// <returns></returns>
Get the local IPv4 address of the same segment as the default gateway.
Get the local IPv4 address of the same segment as the default gateway .
private IPAddress GetLocalPrimaryAddress()
        {
            var prop = NetworkInterface
                .GetAllNetworkInterfaces()
                .Select(i => i.GetIPProperties())
                .FirstOrDefault(p => p.GatewayAddresses.Count > 0);
            if (prop == null)
                return null;
            var v4Addr = prop.UnicastAddresses
                .Select(ua => ua.Address)
                .Where(addr => addr.AddressFamily == AddressFamily.InterNetwork
                                && !IPAddress.IsLoopback(addr))
                .FirstOrDefault();
            return (v4Addr != null)
                ? v4Addr
                : null;
        }
private IPAddress GetLocalPrimaryAddress ( ) { var prop = NetworkInterface . GetAllNetworkInterfaces ( ) . Select ( i => i . GetIPProperties ( ) ) . FirstOrDefault ( p => p . GatewayAddresses . Count > 0 ) ; if ( prop == null ) return null ; var v4Addr = prop . UnicastAddresses . Select ( ua => ua . Address ) . Where ( addr => addr . AddressFamily == AddressFamily . InterNetwork && ! IPAddress . IsLoopback ( addr ) ) . FirstOrDefault ( ) ; return ( v4Addr != null ) ? v4Addr : null ; }
Get the local IPv4 address of the same segment as the default gateway.
Get the local IPv4 address of the same segment as the default gateway .
None