private string NormaliseIPv6Address(string hostname)
 {
     if (hostname == null || !InetAddressUtils.IsIPv6Address(hostname))
     {
         return(hostname);
     }
     try
     {
         IPAddress inetAddress = Sharpen.Extensions.GetAddressByName(hostname);
         return(inetAddress.GetHostAddress());
     }
     catch (UnknownHostException uhe)
     {
         // Should not happen, because we check for IPv6 address above
         log.Error("Unexpected error converting " + hostname, uhe);
         return(hostname);
     }
 }
Exemple #2
0
        private string GetIPAddress()
        {
            var list = Collections.List(NetworkInterface.GetNetworkInterfaces());

            foreach (var intf in list.AsEnumerable())
            {
                if (intf.IsLoopback())
                {
                    continue;
                }
                var addresses = Collections.List(intf.GetInetAddresses());
                foreach (var addr in addresses)
                {
                    if (InetAddressUtils.IsIPv4Address(addr.GetHostAddress()))
                    {
                        return(addr.GetHostAddress());
                    }
                }
            }
            return("?");
        }
        private string BuildString()
        {
            StringBuilder sb = new StringBuilder();

            if (this.scheme != null)
            {
                sb.Append(this.scheme).Append(':');
            }
            if (this.encodedSchemeSpecificPart != null)
            {
                sb.Append(this.encodedSchemeSpecificPart);
            }
            else
            {
                if (this.encodedAuthority != null)
                {
                    sb.Append("//").Append(this.encodedAuthority);
                }
                else
                {
                    if (this.host != null)
                    {
                        sb.Append("//");
                        if (this.encodedUserInfo != null)
                        {
                            sb.Append(this.encodedUserInfo).Append("@");
                        }
                        else
                        {
                            if (this.userInfo != null)
                            {
                                sb.Append(EncodeUserInfo(this.userInfo)).Append("@");
                            }
                        }
                        if (InetAddressUtils.IsIPv6Address(this.host))
                        {
                            sb.Append("[").Append(this.host).Append("]");
                        }
                        else
                        {
                            sb.Append(this.host);
                        }
                        if (this.port >= 0)
                        {
                            sb.Append(":").Append(this.port);
                        }
                    }
                }
                if (this.encodedPath != null)
                {
                    sb.Append(NormalizePath(this.encodedPath));
                }
                else
                {
                    if (this.path != null)
                    {
                        sb.Append(EncodePath(NormalizePath(this.path)));
                    }
                }
                if (this.encodedQuery != null)
                {
                    sb.Append("?").Append(this.encodedQuery);
                }
                else
                {
                    if (this.queryParams != null)
                    {
                        sb.Append("?").Append(EncodeUrlForm(this.queryParams));
                    }
                    else
                    {
                        if (this.query != null)
                        {
                            sb.Append("?").Append(EncodeUric(this.query));
                        }
                    }
                }
            }
            if (this.encodedFragment != null)
            {
                sb.Append("#").Append(this.encodedFragment);
            }
            else
            {
                if (this.fragment != null)
                {
                    sb.Append("#").Append(EncodeUric(this.fragment));
                }
            }
            return(sb.ToString());
        }
 private static bool IsIPAddress(string hostname)
 {
     return(hostname != null && (InetAddressUtils.IsIPv4Address(hostname) || InetAddressUtils
                                 .IsIPv6Address(hostname)));
 }