public NetProxyBypassItem(string value)
        {
            _originalValue = value;

            if (IPAddress.TryParse(value, out _ipAddress))
            {
                _type = NetProxyBypassItemType.IpAddress;
            }
            else if (NetworkAddress.TryParse(value, out _networkAddress))
            {
                switch (_networkAddress.Address.AddressFamily)
                {
                case AddressFamily.InterNetwork:
                    if (_networkAddress.PrefixLength == 32)
                    {
                        _type           = NetProxyBypassItemType.IpAddress;
                        _ipAddress      = _networkAddress.Address;
                        _networkAddress = null;
                        return;
                    }

                    break;

                case AddressFamily.InterNetworkV6:
                    if (_networkAddress.PrefixLength == 128)
                    {
                        _type           = NetProxyBypassItemType.IpAddress;
                        _ipAddress      = _networkAddress.Address;
                        _networkAddress = null;
                        return;
                    }

                    break;
                }

                _type = NetProxyBypassItemType.NetworkAddress;
            }
            else if (DnsClient.IsDomainNameValid(value))
            {
                _type       = NetProxyBypassItemType.DomainName;
                _domainName = value;
            }
            else
            {
                throw new NetProxyException("Invalid proxy bypass value: " + value);
            }
        }
Esempio n. 2
0
        public NetProxyBypassItem(string value)
        {
            _originalValue = value;

            if (IPAddress.TryParse(value, out _ipAddress))
            {
                _type = NetProxyBypassItemType.IpAddress;
            }
            else if (value.Contains("/"))
            {
                string[] network = value.Split(new char[] { '/' }, 2);

                if (IPAddress.TryParse(network[0], out _networkAddress) && int.TryParse(network[1], out _networkMaskWidth))
                {
                    switch (_networkAddress.AddressFamily)
                    {
                    case AddressFamily.InterNetwork:
                        if (_networkMaskWidth > 32)
                        {
                            throw new NetProxyException("Invalid proxy bypass value: " + value);
                        }

                        if (_networkMaskWidth == 32)
                        {
                            _type      = NetProxyBypassItemType.IpAddress;
                            _ipAddress = _networkAddress;
                        }
                        else
                        {
                            _type = NetProxyBypassItemType.NetworkAddress;
                        }

                        break;

                    case AddressFamily.InterNetworkV6:
                        if (_networkMaskWidth > 128)
                        {
                            throw new NetProxyException("Invalid proxy bypass value: " + value);
                        }

                        if (_networkMaskWidth == 128)
                        {
                            _type      = NetProxyBypassItemType.IpAddress;
                            _ipAddress = _networkAddress;
                        }
                        else
                        {
                            _type = NetProxyBypassItemType.NetworkAddress;
                        }

                        break;

                    default:
                        throw new NotSupportedException("Address family not supported.");
                    }
                }
                else
                {
                    throw new NetProxyException("Invalid proxy bypass value: " + value);
                }
            }
            else if (DnsClient.IsDomainNameValid(value))
            {
                _type       = NetProxyBypassItemType.DomainName;
                _domainName = value;
            }
            else
            {
                throw new NetProxyException("Invalid proxy bypass value: " + value);
            }
        }