/// <summary>
 /// Sets up the proxy configuration based on the addresses in <paramref name="allowedProxies"/>.
 /// </summary>
 /// <param name="config">The <see cref="NetworkConfiguration"/> containing the config settings.</param>
 /// <param name="allowedProxies">The string array to parse.</param>
 /// <param name="options">The <see cref="ForwardedHeadersOptions"/> instance.</param>
 internal static void AddProxyAddresses(NetworkConfiguration config, string[] allowedProxies, ForwardedHeadersOptions options)
 {
     for (var i = 0; i < allowedProxies.Length; i++)
     {
         if (IPNetAddress.TryParse(allowedProxies[i], out var addr))
         {
             AddIpAddress(config, options, addr.Address, addr.PrefixLength);
         }
         else if (IPHost.TryParse(allowedProxies[i], out var host))
         {
             foreach (var address in host.GetAddresses())
             {
                 AddIpAddress(config, options, address, address.AddressFamily == AddressFamily.InterNetwork ? 32 : 128);
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Tries to identify the string and return an object of that class.
        /// </summary>
        /// <param name="addr">String to parse.</param>
        /// <param name="result">IPObject to return.</param>
        /// <returns>True if the value parsed successfully.</returns>
        private static bool TryParse(string addr, out IPObject result)
        {
            if (!string.IsNullOrEmpty(addr))
            {
                // Is it an IP address
                if (IPNetAddress.TryParse(addr, out IPNetAddress nw))
                {
                    result = nw;
                    return(true);
                }

                if (IPHost.TryParse(addr, out IPHost h))
                {
                    result = h;
                    return(true);
                }
            }

            result = IPNetAddress.None;
            return(false);
        }
Exemplo n.º 3
0
 public void ValidIPStrings(string address)
 {
     Assert.True(IPNetAddress.TryParse(address, out _));
 }
Exemplo n.º 4
0
 public void TestSubnetContains(string network, string ip)
 {
     Assert.True(IPNetAddress.TryParse(network, out var networkObj));
     Assert.True(IPNetAddress.TryParse(ip, out var ipObj));
     Assert.True(networkObj.Contains(ipObj));
 }
Exemplo n.º 5
0
 public void InvalidAddressString(string address)
 {
     Assert.False(IPNetAddress.TryParse(address, out _));
     Assert.False(IPHost.TryParse(address, out _));
 }
Exemplo n.º 6
0
 public static void TryParse_InvalidAddressString_False(string address)
 => Assert.False(IPNetAddress.TryParse(address, out _));
Exemplo n.º 7
0
 public static Property TryParse_IPv6Address_True(IPv6Address address)
 => IPNetAddress.TryParse(address.Item.ToString(), out _).ToProperty();
Exemplo n.º 8
0
 public static void TryParse_ValidIPStrings_True(string address)
 => Assert.True(IPNetAddress.TryParse(address, out _));